  Operational Insights on Cron. Cron is a very handy and very easy to manage utility(shall I dare call it a utility?). We can manage complex task scheduling by a single line entry in the crontab file. But there are some nuances which we have to note. Very interesting ones. Here goes: I created the following cron entry for one of my poller jobs.
00 0-23 * * * /RAPproj/ConsApps/smsapps/nse/poller/nseTimer.sh To exactly understand this entry, start reading from the begining: 00 : Minutes 0-23 : Hours * : Day of Month * : Month of Year * : Day of Week This will run my following shellscript: /RAPproj/ConsApps/smsapps/nse/poller/nseTimer.sh whenever the minute figure becomes 00; for hours 0-23; for all days; for all years. In effect run my shellscript at every hour. Now take a look at my script nseTimer.sh: rrr=`ps -aef | grep nseTimer | grep "java" | awk '{ print " "$2" " }'` kill -9 $rrr CLASSPATH=j2ee.jar:classes12.jar:ftp.jar:. :/RAPproj/ConsApps/smsapps/nse/poller/ export CLASSPATH nohup java nseTimer & OK to cut the crap for every line above read the description: #Find whether already a process by name nseTimer is running. #If yes Kill it. #Do the classpath settings. #export classpath (I donno what that means but we have to do it anyways) #Start the nseTimer timer class. Now every things fine. When I run this shell script from the directory /RAPproj/ConsApps/smsapps/nse/poller (where it actualy resides) everything works perfect. It finds already running process nseTimer; kills it; and then restarts the same process. But when I make that cron entry run this shell script, what happens is this: 1.It finds the already running script by the same name. 2.Kills it. 3.Then does nothing(It is supposed to restart the process). Well guys...I must admit that I invested 2 long days here just trying to figure this out.
And the correction is this new script: rrr=`ps -aef | grep nseTimer | grep "java" | awk '{ print " "$2" " }'` kill -9 $rrr cd /RAPproj/ConsApps/smsapps/nse/poller CLASSPATH=j2ee.jar:classes12.jar:ftp.jar:. :/RAPproj/ConsApps/smsapps/nse/poller/ export CLASSPATH nohup java nseTimer & Notice the third line here: cd /RAPproj/ConsApps/smsapps/nse/poller This is the directory where my script was residing. Now to summarise this whole story up, I told the cron that where is my shell script (remember the cron entry?
) 00 0-23 * * * /RAPproj/ConsApps/smsapps/nse/poller/nseTimer.sh So I thought that now cron will do its job. It will run the script which will find the nseTimer class and then fire that class(which is in the same directory as the script). But then the script looks for the class file in the current directory. And the current directory here is not the one in which the script is.
But it is the one in which cron resides. So it looks for nseTimer in the directory where cron is and not in /RAPproj/ConsApps/smsapps/nse/poller/ Thats why that line: cd /RAPproj/ConsApps/smsapps/nse/poller saved the day DUH!! now you guys will say what the heck .... for this small intuitive stuff you have written this huge story !!!! But believe me guys.....come to think of it. Now that I have told you this, it sounds intuitive. But if you stand in isolation, its not that intuitive too. Well ... to be honest not for me.... :-D May be my intuition is not that strong. Heheheh And for those of you who are still reading..... whats your name?? we can be good friends you know !! :-) :-) you can go thru the grind of my hopeless blabber. :-) take care 
