Tuesday, 9 August 2011

Crontab,Its Usage and Syntax

cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris.  Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times. It help us to schedule a job under a specific user to do operations automatically,

1. Crontab Commands
 NB: Make sure that you are switched to the specific cron id(user id) before execute all these.
crontab -e      Edit your crontab file, or create a new crontab under specific user
crontab -l      To see crontab
crontab -r      Remove your crontab file.
crontab -v      Display the last time you edited your crontab file.
crontab /dev/null   To nullify a crontab
crontab -u <user>   Used in conjunction with other options, this option allows you to modify or  view the crontab file of user. When available, only administrators can use this option.(Need to be root)
2.General Syntax of Crontab
*    *    *    *    *  command to be executed
┬    ┬    ┬    ┬    ┬
│    │    │    │    │
│    │    │    │    │
│    │    │    │    └───── day of week (0 - 7) (Sunday=0 or 7)
│    │    │    └────────── month (1 - 12)
│    │    └─────────────── day of month (1 - 31)
│    └──────────────────── hour (0 - 23)
└───────────────────────── min (0 - 59)
Eg1a
01,11,21,31,41,51 * * * * /home/wassrvr/a1ibmsvc.gce.sh /home/wassrvr/a1ibmsvc.gce.dat 
This job cron job runs on every 10 minutes,
 Eg1b
Smart people use below one, we can assure both are identical
*/10 * * * */home/wassrvr/a1ibmsvc.gce.sh /home/wassrvr/a1ibmsvc.gce.dat
 This job cron job runs on every 10 minutes,
 Eg2:
* * * * * /web/tools/ihs_logroll.sh > /tmp/ihs_logroll.log 2>&1

They are all still asterisks! So this means

    every minute
    of every hour
    of every day of the month
    of every month
    and every day in the week.

In short: This script is being executed every minute. Without exception.
Eg3:
Cron job  from Tuesday  to Friday at 8 PM 
0 20 * * 2-5 /web/tools/ihs_logroll.sh > /tmp/ihs_logroll.log 2>&1

    minute: 0
    of hour: 20
    of day of month: * (every day of month)
    of month: * (every month)
    and weekday: 2-5 (=Tuesday to Friday)
Mail a cron job
*/10 * * * *  /web/tools/ihs_logroll.sh > /tmp/ihs_logroll.log 2>&1 | mail -s "sub" musthaqpm@yahoo.in

Trashing a crontab or disable mail service
10 * * * * /home/wassrvr/a1wassrv.gce.sh /home/wassrvr/a1wassrv.gce.dat > /dev/null 2>&1
/dev/null can nullify a file,  just pipe the output of the file to /dev/null, which eliminates the  content

How to disable a particular task on a crontab
Just comment the line with  “#” , which disable the task
#31 10 23 * * /system/web/security/scripts/wasHealthCheck.ksh 
In various environment,  If we do changes, cron jobs could be disabled,  If we have  lot of task to be uncomment is bit difficult task, There we used to remove the crontab after taking the backup of the crontab, Once change has implemented we enable the backup file of the cron.
Backup of cron:
wassrvr@g01cdwps003:~> crontab -l > /tmp/crontab.musthaq.bkp   #Backup 
wassrvr@g01cdwps003:~> ls -lrt /tmp/crontab.musthaq.bkp
-rw------- 1 wassrvr websrvr 427 2011-08-13 20:29 /tmp/crontab.musthaq.bkp
wassrvr@g01cdwps003:~>crontab -r     #remove crontab
Enable the cron 
wassrvr@g01cdwps003:~>crontab /tmp/crontab.musthaq.bkp    #load the crontab again 

Cron permissions

The following two files play an important role:
§  /etc/cron.allow - If this file exists, then you must be listed therein (your username must be listed) in order to be allowed to use cron jobs.
Noramlly, it could be removed from the server, since its difficult to enter the name of the people, who really want to use crontab, its tough for root to monitor this, Most of the environment we cant see cron.allow  file
§  /etc/cron.deny - If the cron.allow file does not exist but the /etc/cron.deny file does exist, then you must not be listed in the /etc/cron.deny file in order to use cron jobs.
musthaq@g01zexwas002:/> ls -lrt /etc/cron.deny
-rw------- 1 root root 11 2010-02-19 11:49 /etc/cron.deny
musthaq@g01zexwas002:/>  sudo cat /etc/cron.deny
musthaq's password:
guest
gast
musthaq@g01zexwas002:/>


Wednesday, 6 July 2011

How to find db2 version

You can use these commands to find the db2 versions
1.
$ db2level  #it displays db2 version
Better to run this under the bin directory of db2 package has been installed
eg:  
$ pwd
/opt/IBM/db2/V9.5_FP2a/bin
 because db2level script has placed under bin directory
2
$db2licm -l   # this one also show the db2 version
 Here you first switch to db2 instance name and do this command to see the version
 3. If both method's don't workout we can try this , Go to installation logs of db2, there you can see the version in the logs 
eg:  path
/opt/IBM/db2/V9.5/logs
$ ls -lrt
total 48
-rw-r--r--    1 root     system          284 Apr 17 04:59 vrmfis.history
-rw-r--r--    1 root     system        16390 Apr 17 04:59 db2install.history
do tail -f on  vrmfis.history, bottom line we can see the version info





If  you are user of Administrative Console of WebSphere, you can find the db Version info from there also

















Tuesday, 5 July 2011

How to remove "^M" (CTRL-M) characters

I used to see "^M" (CTRL-M) characters, when  i receive files via email or any other messengers, i could see this, 
you can use the these 2 methods to eliminate the "^M" (CTRL-M)

1.
$ vi <filename>
      [press Esc] then Enter  :%s/[ctrl-v][ctrl m]//g


2.
perl -pi -e 's/\r\n/\n/;' <filename>

eg: perl -pi -e 's/\r\n/\n/;' ApplicationResources.properties 



How to find CPU utlization on AIX and Linux

In AIX , we can use "topas" command to find the cpu utilization

$topas   #which displays the cpu utilization of  each process on AIX
Here we can see
1. PID of the process
2.Name of the process
3.CPU utilization
4.PgSP - Page Space
5. Owner of the process

Similarly in Linux we can use  "top"  command