Monday, 15 August 2011

Install Firefox Web Browser (OpenBSD)


How do I install Mozilla Firefox which is a free and open source web browser under OpenBSD operating systems?

You can install Mozilla Firefox using the pkg_add command as follows. Open a command-line terminal. Switch to the root user by typing su - and entering the root password, when prompted. Type the following command:
# export PKG_PATH=http://ftp.plig.net/pub/OpenBSD/4.9/packages/`machine -a`/
# pkg_add -v mozilla-firefox

Sample outputs:
mozilla-firefox-3.6.13p3:nspr-4.8.7: ok
mozilla-firefox-3.6.13p3:libiconv-1.13p2: ok
mozilla-firefox-3.6.13p3:gettext-0.18.1p0: ok
mozilla-firefox-3.6.13p3:pcre-8.02p1: ok
mozilla-firefox-3.6.13p3:libgamin-0.1.10p3: ok
mozilla-firefox-3.6.13p3:glib2-2.26.1p0: ok
mozilla-firefox-3.6.13p3:desktop-file-utils-0.17: ok
mozilla-firefox-3.6.13p3:cairo-1.10.2: ok
mozilla-firefox-3.6.13p3:pango-1.28.3p2: ok
mozilla-firefox-3.6.13p3:libxml-2.7.8p1: ok
mozilla-firefox-3.6.13p3:shared-mime-info-0.80: ok
mozilla-firefox-3.6.13p3:atk-1.32.0: ok
mozilla-firefox-3.6.13p3:jasper-1.900.1p1: ok
mozilla-firefox-3.6.13p3:gdk-pixbuf-2.22.1: ok
mozilla-firefox-3.6.13p3:hicolor-icon-theme-0.12: ok
mozilla-firefox-3.6.13p3:gtk+2-2.22.1: ok
mozilla-firefox-3.6.13p3:sqlite3-3.7.4: ok
mozilla-firefox-3.6.13p3:nss-3.12.9: ok
mozilla-firefox-3.6.13p3: ok
Look in /usr/local/share/doc/pkg-readmes for extra documentation.
You can start Firefox using the following command or GUI menu options:
$ /usr/local/bin/firefox &

Linux Delete / Remove MBR

I've installed an usb image on Pen drive along with MBR. Now, I need to use this USB pen for other purpose. Is there a way in Linux to delete the mbr (just like dos fdisk /mbr command)?

You can delete the mbr (master boot recored) using the dd command itself. The following command will completely delete your MBR, which contains all your partition information. So make sure you use the correct device name:
# dd if=/dev/zero of=/dev/sdc bs=512 count=1
Sample outputs:
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.00308483 s, 166 kB/s
/dev/sdc is your USB pen device.

Create Slackware Linux Bootable USB Pen Drive



How do I Install Slackware Linux version 13.13 using a bootable USB stick under Unix or Linux operating systems?

First, you need to download Slackware Linux version 13.13 using the wget command as follows:
$ cd /tmp
$ wget ftp://slackware.osuosl.org/pub/slackware/slackware-13.37/usb-and-pxe-installers/usbboot.img

To create a bootable usb stick, enter:
# cd /tmp
# dd if=usbboot.img of=/dev/sdc bs=512

Where,
  1. usbboot.img - It is a 30MB small USB boot image that you can use to boot into the Slackware setup program.
  2. /dev/sdc - USB stick

BIOS Boot Options

Your computer BIOS must support booting from USB HDD.
  • Start your computer.
  • Press [DEL] or [F2] to enter into BIOS setup ( this step is dependent on the type of computer you have, see your computer manual for more info).
  • Make sure boot option is set to USB Hard disk.
  • Plug the USB stick into your computers USB slot
  • Boot the system up.
The Slackware Linux installer will start. Log in as root. Use fdisk or cfdisk command to create partitions:
# cfdisk /dev/sda
OR
# fdisk /dev/sda
To start the install type setup command:
# setup
You can now install packages from a CDROM, hard disk or network locations.

Nginx Redirect URL With HTTP/1.1 301 Moved Permanently Header


How do I redirect old ugly urls such as http://example.com/store/view.jsp?product=foo with clean url - http://example.com/store/view/product/foo using nginx reverse proxy?

You need to use HttpRewriteModule under nginx web server. This module makes it possible to change URI using regular expressions (PCRE), and to redirect and select configuration depending on variables. The syntax is as follows to chage URI in accordance with the regular expression and the replacement string.
 
rewrite regex replacement flag
 
Please note that directives are carried out in order of appearance in the configuration file. Here is sample configuration for the same:
 
# rewrite urls
rewrite ^/store/view/product/(.*) /store/view.jsp?product=$1  permanent;
## Uncomment the following line to redirect old urls with HTTP/301 ##
# rewrite "^/store/view.jsp?product=(.*)$" ^/store/view/product/$1 permanent;
 
Here is another example with try_files directive which checks for the existence of files in order, and returns the first file that is found:
 
### Add inside server { ... } directive block ###
### Only works with Nginx version 0.7.65+ ###
        location / {
                index store.php;
                try_files $uri $uri/ @ourcleanurls;
        }
        # rewrite urls #
        location @ourcleanurls {
                rewrite ^/media/(.*) /includes/cache/helper.php?m=$1&images=1 last;
                rewrite ^/css/(.*) /includes/cache/helper.php?m=$1&css=1 last;
                rewrite ^/js/(.*) /includes/helper.php?m=$1&js=1&c=false last;
                rewrite ^/(.*) /store.php?pid=$1 last;
        }
 
You need to reload the nginx server using the following command:
# /usr/local/nginx/sbin/nginx -s reload

How Do I Test New Changes?

You can use the curl command to test new changes including HTTP/1.1 301 Moved message:
$ curl -I http://example.com/store/view/product/foo
$ curl -I http://example.com/store/view.jsp?product=foo

How do I shutdown remote Linux or UNIX system from MS-Windows system?

You can use secure shell (ssh), a network protocol for remote administration of Linux and Unix based computers. SSH is typically used to log into a remote server and execute commands such as reboot or shutdown.

PuTTY SSH Client

PuTTY is a free and open source terminal emulator application which can act as a client for the SSH under MS-Windows operating system. Visit this page and download putty client. In order to use putty you need to know:
  • IP or Server Name: The name of the Linux or UNIX server you want to connect to.
  • Username and password: Login name or password to used on your server.
If you don't know what login name or password to use, contact the administrator of your server.
MS-Windows Running PuTTY  To Shutdown Remote UNIX / Linux System
Fig.01: Putty in action

Once connected you need to login as root using sudo or su - command. Type the following command to shutdown remote system:
# shutdown -h now
OR
# /sbin/shutdown -h now
To reboot the system, enter:
# shutdown -r now
OR
# /sbin/reboot
A typical login session - PuTTY running on Windows, logged in to a DD-WRT Linux based Internet router system:
PuTTY running a session on Windows, logged into Linux system
Fig.02: PuTTY running a session on Windows, logged into Linux system

TCSH / CSH / C Shell Check Whether a Directory is Empty or Not


How do I check whether a directory is empty or not under Linux / UNIX using a TCSH / C shell script?

You can use the following simple code to check if a directory is empty or not using csh:
 
#!/bin/csh
set dir="$1"
set c=0
# make sure $dir exits
if ( -d ${dir} ) then
    set c=`ls -a ${dir} | wc | awk '{print $1}'`
   # IS dir is empty
    if ( "${c}" == 2 ) then
		echo "Empty directory - "${dir}
    else 	#dir has files
		echo "Dir has files - "${dir}
    endif
else
      echo "Error: Not a directory"
endif
 
You can use the find command (see your local find man page for exact syntax) as follows:
 
find "/path/to/dir" -type f -exec echo Found file {} \;
 
OR
 
find -type d -empty

Slow DNS on Linux with IPv4 and IPV6 Configured Firewall


I'm getting slow DNS response from ssh and other network related traffic with delay of 30-60+ seconds per connection. All of our servers are behind hardware based dedicated firewall. My RHEL v6.1 server system running on HP hardware. How do I fix this problem?
This is well known problem with RHEL 6 based systems and can be fixed by adding the following line to /etc/resolv.conf
 
options single-request-reopen
 
Save and close the file. This should fix the problem as the resolver uses the same socket for the A and AAAA requests. Turning this option on changes this behavior so that if two requests from the same port are not handled correctly it will close the socket and open a new one before sending the second request[1].

References:

  • [1] This solution is documented RHN KB ID # 58626 (Red hat subscription required)
Browser Name:
Browser Version:
Browser Code Name:
User-Agent: