Tuesday, October 26, 2010

Get date information from commands.

Get the Date output.
===============
$ date +%d -- Date
26
$ date +%D -- Date format
10/26/10
$ date +%m -- Month
10
$ date +%b -- Month
Oct
$ date +%M -- Minutes
45
$ date +%W -- Week of the year
43
$ date +%w -- Week of the day
2
$ date +%Y -- Year
2010
$ date +%y -- Year (last 2 digits)
10
$ date +%n -- New line
$ date +%l -- hour (0..12)
4
$ date +%k -- hour (0..23)
16
$ date +%N -- nano seconds
855022663
$ date +%T -- time format
16:48:14
-----------------------------------
$ set `date`
$ echo $1
Tue
$ echo $2
Oct
$ echo $3
26
$ echo $4
16:52:45
$ echo $5
IST
$ echo $6
2010
$ echo $# -- Total number of command variables.
6
-----------------------------------------------
date |cut -d" " -f1 # Replace f1 to f2,3,4,5,6 to get the values.
Tue
-------------------------
You can run a loop to check the day and run some commands according using case loop.

case `date |cut -d" " -f1` in
Mon) commands ;;
Tue) commands ;;
Wed) commands ;;
...
esac

Monday, October 25, 2010

Check top CPU or Memory utilisation process.

Find Processes that uses maximum processor utilisation
#ps -eo pid,ppid,pcpu,rss,cmd --sort pcpu

Find Processes that uses maximum Memory utilisation
#ps -eo pid,ppid,pcpu,rss,cmd --sort rss

Kill multiple jobs OR Kill all jobs of a particular user

# Create a list of specific jobs of a user
ps -ef |grep [username]|grep [jobname eg. telnet]|awk '{print $2}' > /tmp/fileout
while read userpid; do kill -9 $userpid;done < /tmp/fileout