Scheduling Cron job-Problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Scheduling Cron job-Problem
# 1  
Old 08-03-2009
Scheduling Cron job-Problem

Hello All,

I want to run a script for every 5 minutes interval.So i developed a script which has to be scheduled to run for every 5 minutes. That script internally runs another script. But the problem is it is not executing properly. Can anybody throw some light on this.

Below are the code snippets for the two scripts.

the first script FirstScript.sh

LogMessage ()
################################################################################
# #
# Write message to log file. #
# #
################################################################################
{
echo "`date` - ${*}" >> $path/applicationLogFile.log
}

ps -e |grep "SecondS*"
scriptStatus=$?
if [ -f $inputfile ]
then
if [ $scriptStatus -ne 0 ]
then
LogMessage "The input file is found."
LogMessage "Initiating RVPMIG2X script"
sh $path/RVPMIG2Xdummy.sh
else
LogMessage "The script is already running.Can not initiate again"
fi
else
LogMessage "The input file is not found"
fi

My SecondScript.sh is as follows:

#! /bin/ksh
echo "Starting the dummy script."
sleep 620
echo "Ending the Script."

Though my second script sleeps for 620 seconds that means for about more than 10 mins but the inner else block is never getting invoked.

i set the cron job as

0,5,10,15,20,25,30,35,40,45,50,55 * * * * sh FirstScript.sh.

when i run the FirstScript normally it is working perfectly fine but when i put it in cron job it is not. Can anybody tell me for this erratic behaviour?

Thanks a lot in advance.

RSC1985

---------- Post updated at 02:44 AM ---------- Previous update was at 02:43 AM ----------

In the code snippet instead of RVPMIG2Xdummy.sh please treat it as SecondScript.sh
# 2  
Old 08-03-2009
what error you are getting? (cron logs?)
# 3  
Old 08-03-2009
I'm not getting any error.All the time it logs the messages

The input file is found.
Initiating RVPMIG2X script

though the script is still running it is entering into if block logs the above messages.

---------- Post updated at 06:20 AM ---------- Previous update was at 03:33 AM ----------

Can anyone suggest me a way to resolve this issue?
# 4  
Old 08-03-2009
Hi,

Can you provide the output of the ps -e |grep "SecondS*" command when the SecondScript.sh is running ?
Personally I would use "ps -ef | grep SecondScript | grep -v grep".
It can be that the "ps -e" output from the user shell and that of the cron shell is different.

E.J.
# 5  
Old 08-03-2009
Where is $path set ?
Where are the scripts located? Are they in the root directory?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Scheduling cron job

Hi Everybody, I want to run a script at every 5 seconds. I know how to run it every 5 minutes, is there any possibility to run a script at 5 seconds interval. Regards, Mastan (3 Replies)
Discussion started by: mastansaheb
3 Replies

2. Solaris

Problem with a cron job

When i am trying to open crontab throught command crontab -e. It is not opening? OUTPUT: # crontab -e sh: vim: not found The crontab file was not changed. Please let me know how to open and edit it??? (10 Replies)
Discussion started by: kkalyan
10 Replies

3. UNIX for Dummies Questions & Answers

Cron job problem

I have a perl script which Im planning to run every minute. I have set the cron job as * * * * * PATH= /usr/local/bin:/usr/bin:/usr/sbin:/usr/lib; perl /dm2/www/html/isos/pre5.3/autoDownload.pl I assume the script is executing every minute only because I see a entry like below when I do... (2 Replies)
Discussion started by: srijith
2 Replies

4. Shell Programming and Scripting

Cron Job Scheduling

Hi All, I have a script which is scheduled in the Cron. It runs every 10th and 40th min of an hour.The job has to run every 30min. But, I do not want to have the 00:10 MST run every day.Is it possible to exclude that run from the schedule?Or any other way through which i can run my job every... (4 Replies)
Discussion started by: sparks
4 Replies

5. Shell Programming and Scripting

Problem with Cron job

Hi , I have a TCL script which i am supposed to run as a cron job.. The script works fine from command line , but when run as a cron job , its unable to find a package,, my crontab is as follows. --------------------------- #!/usr/bin/ksh * * * * * PATH=/cm8/auto/Automation/Library/TclLib ... (7 Replies)
Discussion started by: Sudharshana
7 Replies

6. Solaris

problem with cron job

new to unix here, im learning how to schedule jobs with crontab. The following cron job runs under root but not under a test account i created. 50 11 * * 0 /usr/bin/banner "HELLO" > /dev/console i have no idea with it isn't running under the test account but runs right on time when i create... (7 Replies)
Discussion started by: solne
7 Replies

7. Solaris

cron job problem

I am trying to setup cronjob and once I start to save it is not working. This is what I am getting after I executed crontab -e, I am not even getting the privious entry and I am running from root. crontab -e 421 10 3 * * * /usr/sbin/logadm ? :wq ? Why is it not saving? Any input is... (4 Replies)
Discussion started by: mokkan
4 Replies

8. UNIX for Dummies Questions & Answers

Problem with scheduling a shell script on cygwin using cron

Hi, Before I start, I would like to inform that, I went through all FAQs and other threads before posting here. I 'm trying to schedule a shell script on cygwin using cron. No matter what I do I don't seem to get the cron job executing my bash script. My script is temp.sh echo `date` >... (4 Replies)
Discussion started by: shash
4 Replies

9. UNIX for Advanced & Expert Users

cron job scheduling

Hi, How can I configure cron file , to execute a script on evey alternate saturdays ? I am using AIX 5.0 machine Thanks in advance Shihab (1 Reply)
Discussion started by: shihabvk
1 Replies

10. UNIX for Dummies Questions & Answers

problem with scheduling a job

I scheduled 2 Oracle jobs to run on IBM AIX 4.3.3 at 06:50 and 06:58 on 02/02/03 with the below syntax: $ at 06:50 02/02/03 /orac/ora11/temp/sun_job1.sh Job oracle.1044175800.a will be run at Sun Feb 2 06:50:00 2003. $ at 06:58 02/02/03 /orac/ora11/temp/sun_job2.sh Job... (1 Reply)
Discussion started by: ted
1 Replies
Login or Register to Ask a Question