Wednesday, June 22, 2011

Unix Shell Basics


Unix Shell Basics: Interview tips on fundamentals

Here we discuss on the Bash shell fundamentals.


bash-3.00# last
root pts/3 :0.0 Wed Jun 22 13:03 still logged in
root console :0 Wed Jun 22 12:57 still logged in
reboot system boot Wed Jun 22 12:49
reboot system down Mon Jun 20 18:24
root pts/3 :0.0 Sun Jun 19 20:25 - 18:23 (21:58)
root console :0 Sun Jun 19 20:25 - 18:23 (21:58)
root pts/3 :0.0 Sun Jun 19 20:15 - 20:24 (00:09)
root console :0 Sun Jun 19 20:10 - 20:25 (00:14)
reboot system boot Sun Jun 19 20:00
reboot system down Sun Jun 19 19:58
root pts/3 :0.0 Sun Jun 19 19:56 - 19:57 (00:00)
root console :0 Sun Jun 19 19:54 - 19:57 (00:03)
reboot system boot Sun Jun 19 19:45
wtmp begins Sun Jun 19 19:45

For eg, if we execute the above command, the system displays the information related to who is currently logged in, in which console the user is logged in, previous user’s login time and terminal worked, when the system is restarted.

Also the information is read from the file /var/adm/wtmpx


Note:
The format of the file is,
bash-3.00# file wtmpx
wtmpx: data



bash-3.00# last reboot
reboot system boot Wed Jun 22 12:49
reboot system down Mon Jun 20 18:24
reboot system boot Sun Jun 19 20:00
reboot system down Sun Jun 19 19:58
reboot system boot Sun Jun 19 19:45
wtmp begins Sun Jun 19 19:45

If we execute the above command, the system displays the information only about, when the system is rebooted.


bash-3.00# last | grep reboot
reboot system boot Wed Jun 22 12:49
reboot system down Mon Jun 20 18:24
reboot system boot Sun Jun 19 20:00
reboot system down Sun Jun 19 19:58
reboot system boot Sun Jun 19 19:45

If we execute the above command, the system displays only when the system is rebooted.
Here pine-line (pipe-line) takes the output of last as the input for the command grep.
Note: Generally the syntax of the command grep is as follows,

$ grep
Eg, $ grep root /etc/passwd.


But in the above eg, we failed to mention the name/path of the file, hence the output of ‘last’ command will be taken as input for ‘grep’ command.


Also we can note the output of the above command is similar to the output of # last reboot.




bash-3.00# last;reboot
root pts/3 :0.0 Wed Jun 22 13:03 still logged in
root console :0 Wed Jun 22 12:57 still logged in
reboot system boot Wed Jun 22 12:49
reboot system down Mon Jun 20 18:24
root pts/3 :0.0 Sun Jun 19 20:25 - 18:23 (21:58)
root console :0 Sun Jun 19 20:25 - 18:23 (21:58)
root pts/3 :0.0 Sun Jun 19 20:15 - 20:24 (00:09)
root console :0 Sun Jun 19 20:10 - 20:25 (00:14)
reboot system boot Sun Jun 19 20:00
reboot system down Sun Jun 19 19:58
root pts/3 :0.0 Sun Jun 19 19:56 - 19:57 (00:00)
root console :0 Sun Jun 19 19:54 - 19:57 (00:03)
reboot system boot Sun Jun 19 19:45
wtmp begins Sun Jun 19 19:45

If we execute the above command, the system displays the information related to who is currently logged in, in which console the user is logged in, previous user’s login time and terminal worked, when the system is restarted and then reboot the system. This is because the two commands are separated by semi-colon (;).



bash-3.00# last | reboot
Now, if we execute the above command, the output of last command will be taken, and the system reboot.




Note: Sun Fire 3500 Back Panel View is displayed in this page.

No comments:

Post a Comment