Wednesday, October 12, 2011

To Capture/Record Unix command

There is way to record/capture what ever commands executed in Unix. You can use 'script' command where all the command dumped to a file that we specify and this process executed at the background. This is very useful when we do some software installation and we are able to capture all the steps and commands that we used.

#script ApacheInstallationSteps.txt
Script started, file is ApacheInstallationSteps.txt
#
#exit
Script done, file is ApacheInstallationSteps.txt
#

Friday, October 7, 2011

Linux:Steps to change root password

Steps to change root password:

1)When GRUB is started press any key followed by 'a' to modify the kernel arguments before booting.

2) Add 1 or single at the end of line and press 'b' to boot to the single user mode.

3) Once single user mode started you can run 'passwd' command to set new password for 'root'.

4) Exit or reboot the server once password has been reset.

LSOF command

Usage example:

#lsof -i TCP (Show all open TCP files)

#lsof -i TCP:80 (Show open TCP files on port 80)

#lsof -c passwd (to find out what files opened when execute this command)

#lsof /dev/sda3 ( which files opened for a device)

Friday, January 28, 2011

Add Virtual IP in Linux

Steps to add virtual IP.

1)Copy existing device etho to new virtual device.
#cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1

2)Edit device and IP address in ifcfg-eth0:1
#vi ifcfg-eth0:1

3)Restart the network service
#service network restart

4)Verify the virtual device is up. You'll see 2 different IP address.I've purposely hide the IP address,Bcast and Netmask. You should get the reply once ping.

# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:50:56:BE:00:3B
inet addr:xx.x.xxx.184 Bcast:xx.x.xxx.xxx Mask:xxx.xxx.xxx.x
inet6 addr: fe80::250:56ff:febe:3b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:36 errors:0 dropped:0 overruns:0 frame:0
TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3751 (3.6 KiB) TX bytes:4480 (4.3 KiB)

eth0:1 Link encap:Ethernet HWaddr 00:50:56:BE:00:3B
inet addr:xx.x.xxx.185 Bcast:10.9.135.255 Mask:255.255.248.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
#ping xx.x.xxx.185
PING xx.x.xxx.185 (xx.x.xxx.185) 56(84) bytes of data.
64 bytes from xx.x.xxx.185: icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from xx.x.xxx.185: icmp_seq=2 ttl=64 time=0.018 ms

Wednesday, January 26, 2011

NOHUP:Running a process and log out

Nohup is a POSIX command to ignore the HUP (hangup) signal, enabling the command to keep running after the user who issues the command has logged out. The HUP (hangup) signal is by convention the way a terminal warns depending processes of logout.

nohup is most often used to run commands in the background as daemons. Output that would normally go to the terminal goes to a file called nohup.out if it has not already been redirected. This command is very helpful when there is a need to run numerous batch jobs which are inter-dependent.

If you redirect the streams you can avoid filling up your filesystem with nohup.out files as follow:


$ nohup tar czf /backup/home.tgz . > /dev/null 2>&1

Sunday, January 23, 2011

Adding File System swap(Solaris)

The Solaris OS supports applying swap to a file. To enable a file system swap you need to perform the following tasks:

1. Create a file using mkfile:

#mkfile 250m /opt/myswapfile (can be done in any partition)
This will create a 250 Meg file, which the Solaris OS can use for swap.

2. To use this swap file, enable it with the following command:

#swap -a /opt/myswapfile
3. Check your change:

#swap -l
Note: To enable the new swap file at the next system boot, add the following entry to /etc/vfstab:

/opt/swapfile - - swap - no -

Disabling swap Space
The Solaris OS provides the ability to disable a swap file while the system is running. This is done with the -d option for swap. All allocated blocks are copied to other swap areas.
solaris# swap -d /opt/myswapfile
To check your change, type this:

solaris# swap -l

Saturday, January 22, 2011

Increase your available swap space with a swap file(Linux)

1)At a command line, type swapon -s (you might need to prepend /sbin/ if you're not root). The command should produce a message that looks something like this:

Filename Type Size Used Priority
/dev/hda2 partition 128044 92472 -1

2)Running df -m (short for "disk free") from a command line should produce output something like this:

Filesystem 1M-blocks Used Available Use% Mounted on
/dev/hda1 11443 6191 5252 55% /


3)dd if=/dev/zero of=/extraswap bs=1M count=512
replacing 512 with the number of megabytes you want in your auxiliary swap file. if= and of= are short for infile and outfile. The /dev/zero device file will give us zeroes to be written to the output file. If you want this file on a different partition, say your /var partition, you would replace /extraswap with /var/extraswap.

Again as root, carefully type:

4)mkswap /extraswap

5)swapon /extraswap.

6)swapon -s we should see our existing swap partition and our new swapfile. Also, the free command should show an increase in total swap space.

7)cp /etc/fstab /etc/fstab.mybackup and add the following entry same like existing:

/dev/hda2 none swap sw 0 0 (Existing swap partition)

/extraswap none swap sw 0 0 (New swap file)

Make sure the entry in the fstab file is correct to avoid problem during boot up.