Tuesday 20 September 2016

Working with Crontab in Linux Environment

Hello All,

We have often worked with schedulers to run a task on a set frequency i.e. daily, weekly or hourly. In windows we use Task Scheduler to run a task at a specified interval. Recently i had to schedule a daily task in Linux environment so like windows task scheduler we have Cron process in Linux.which runs in background and executes scheduled process. A detailed description is given in the following article http://www.howtogeek.com/101288/how-to-schedule-tasks-on-linux-an-introduction-to-crontab-files/ 

To List out some Important commands in Brief :

Listing Crontab - crontab -l
Editing Crontab - crontab -e
Opening Crontab in Edit Mode - i (Insert Mode)
Escape Crontab - Esc (Brings Crontab in Read Only Mode)
Exit Crontab - :q
Exit and Save Crontab - :wq

Setting The Frequency of Running Tasks :

minute(0-59) hour(0-23) day(1-31) month(1-12) weekday(0-6) command

i.e. 30 7 1 12 * /siebel/export.sh

the command translates to , run export.sh file every 12th Month(December) on 1st day at 7 hrs 30 minutes
* in the crontab represent no validation so, 

30 7 * * * /siebel/export.sh, represents run export.sh every day at 7 hrs 30 minutes 

Issue faced with SQL Data Export using Crontab  :

I was running a Task to Export data from table to a shared location, i implemented this by Spooling a SQL file and Calling the File from a shell script(.sh) then set its frequency to run daily.
If i ran the .sh file manually from command terminal it was running fine with SQL export files generated in specified directory, but after scheduling it in cron tab log files were generated but no SQL export files were being generated.
After much of research, re verifying syntax and hit and trial i realized i was missing some very important points.


  • I did not specify the target directory in shell file where i wanted my export files to be generated, since while running manually from terminal i had placed my .sh file in same location so export files were generated 
  • While running in Cron tab since there was no explicit directory specified field were being generated under /HOME location
  • The issue resolved after i specified target directory path before SQL export was called.

No comments:

Post a Comment

Siebel GoTo View - Handling Realtime cases

 Hello All,  We all must have used GoTo view functionality of siebel to navigate to a particular view from current view. What if the require...