CRONTAB
Cron is unix,solaris utility that allows tasks to be automatically run in the background 
         At regular intervals by the cron daemon.
Crontab is a file which contains the schedule of cron entries to be run and at specified
          Times.
Crontab commands:
        
        Crontab –e       edit crontabfile 
        
        Crontab –l        display current crontab entries
        Crontab –r        remove crontabfile
        Crontab – v display the last time edited
Crontab syntax:
   
       A crontab file has five fields for specifying day,date and time 
   
       Each line in the crontab follows the following format
 
        *  *  *  *  * 
                   Field                   meaning  
                   
1minute(0-59)
2hour(0-23)
3day of month(1 -31)
4month (1-12)
5day of week(0-6)  (Sunday=0)
how to edit crontab:
         1 .   At the prompt type in ‘crontab –e’ .This will open crontab file when this file open you will see other cron jobs ,or if u haven’t any-you’ll see a branch of lines with ‘~’ on them.
2 .use the cursor to go down until you can’t move the cursor down any more.this is where you start your new line.press ‘o’ to insert a new line.
3. press ‘o’ to insert new line.if u want to edit line,press’I’.
4. press the ‘esc’ key to exit out of edit mode.
5. to save the changes and exit :zz
    If u want to exit without saving changes:q!
6. to view the new entry in crontab file type ‘crontab-l’.this will list the contents of crontabfile.
Crontab environment:
Cron invokes the  command from the user’s  HOME directory with the shell
Upon the execution of a command from a crontab entry,the implementation will supply a default environment ,defining at least the following environment variables
HOME    
              A pathname of the user’s home directory.
LOGNAME
            The users login name
PATH   
             A string representing a search path guaranteed to find all of the standard           
             Utilities.
SHELL 
          A pathname of the command interpreter.
Crontab example:
                                                                                                                                                                         
5,10,15,20,25,30,35,40,45,50,55 * * * * /pro.sh >> /var/log/pro.log
              
                      
                               On the 5th minute
                               Every hour of  the day
                               Every day of the month
                               Every month of the year
                               Every day of the month
It will run pro.sh
               
su - applprod -c 'sh fam.sh'
cp /prodapps/applprod/process.lst .
if [ `tail -1 process.lst | awk '{print $1}'` -gt 500]
then
echo "Bouncing Apache"
sh /bounce.sh
fam.sh
sqlplus -s apps/apps <set feed off
set linesize 100
set pagesize 200
spool process 
SELECT count(*) from v\$process;
spool off
exit
!
if [ `tail -1 process.lst | awk '{print $1}'` -gt 500 ]
then
echo "Apache to be bounced"
 
once the processes reaches 500 it will bounce 
Disable email:
         By default cron jobs sends a email to the users account executing the  cronjob. If this is  not required  put the following  command at the end of the cronjob line.
>/var/null 2>&1
Generate log file:
    To collect the cron execution execution log in a file:
     
 >>ar/log/pro.log
Thursday, May 8, 2008
Crontab
Posted by V.R.Kishore Reddy at 23:53
