Thursday, October 20, 2011

Set PATH variable in UNIX

The PATH environment variable is a colon-delimited list of directories that your shell searches through when you enter a command.

Program files (executables) are kept in many different places on the Unix system. Your path tells the Unix shell where to look on the system when you request a particular program. Having more directories in your path will reduce the number of times you get "Command not found" errors, but might put you at greater risk of activating a Trojan horse.
To find out what your path is, at the Unix shell prompt, enter:
echo $PATH
Your path will look something like the following.
/usr2/username/bin:/usr/local/bin:/usr/bin:.

You will see your username in place of username. Using the above example path, if you enter the ls command, your shell will look for the appropriate executable file in the following order: first, it would look through the directory /usr2/username/bin, then /usr/local/bin, then /usr/bin, and finally the local directory, indicated by the . (a period).

To modify your path
If you are using csh or tcsh, at the shell prompt, enter:
setenv PATH $PATH\:/dir/path

If you are using sh, ksh, or bash, at the shell prompt, enter:
PATH=$PATH\:/dir/path ; export PATH

In all cases, replace /dir/path with the directory you want the shell to search.

Note: The earlier entries in the path take precedence over the later ones. If you want the directories you add to your path to take precedence, in the examples above, replace $PATH\:/dir/path with /dir/path:$PATH .

To make these changes permanent, add the commands described above to the end of your .cshrc file (for csh and tcsh), .profile file (for sh and ksh), or .bash_profile file (for bash).

Source: http://kb.iu.edu/data/acar.html
Have a nice day!

Solaris "sys-unconfig" to modify basic settings


Sometimes, we run into chnaging hostname, ipaddress and network settings on Sun Solaris servers. We can do it by modifying /etc/hosts, /etc/hostname."nic", netmasks, nodename and etc. But modyfying these files won't change network settings or hostname in some situations. In these situations our best tool is "sys-unconfig".


Friday, October 7, 2011

Moving /usr, /var & /opt to a different partition in Solaris

1. Add new hard drive to make new partitions


2. Boot server with cdrom in single user mode # boot cdrom –s

3. Mount the partition where we are copying from # mount –o rw /dev/dsk/c1t0d0s0 /mnt

4. Mount the partition where we are copying to # mount –o rw /dev/dsk/c1t2d0s0 /mnt/test

5. Go to /mnt/test folder – # cd /mnt/test

6. Run this command to copy stuff # ufsdump 0f - /mnt/usr | ufsrestore rf –

7. Go to # cd /mnt/test/usr and run “mv * ..”

8. The above step copy all files form usr sub folder to root folder

9. Go to # cd /mnt/test

10. Make a dir local # mkdir /mnt/test/local

11. Type cd /

12. # umount /mnt/test

13. DO above steps from 4 to 9 for moving var folder

14. Creat a subfolder “run” under /var folder on new partition /mnt/test # mkdir /mnt/test/run . This is very critical for coming root in multiuser mode.

15. Type cd /

16. #umount /mnt/test

17. Do above steps for moving “opt” folder for steps 4 to 12 except step 10

18. Type cd / ; #umount /mnt/test

19. Now go to the /mnt folder (Which is the main root file system)

20. Move directories to # mv usr usr.bak ; # mv var var.bak ; # mv opt opt.bak to roll back all changes if needed

21. Create usr, var and opt folders # mkdir usr, #mkdir var; #mkdir opt

22. Some time the newly created usr folder needs these parameters to set # chown root /mnt/usr; #chgrp sys /mnt/sys; #chmod 755 /mnt/usr

23. Modify the vfstab file # EDITOR=vi; # export vi; # TERM=vt100; # export TERM; # vi /mnt/etc/vfstab and do respect changes

24. Do not forget “-“ mount option at the end and it looks like

25. “ /dev/dsk/c1t2d0s0 /dev/rdsk/c1t2d0s0 /usr ufs 1 no - “

26. Reboot or STOP +a boot -ar