Cron is not working redhat linux

jayatallen
jayatallen used Ask the Experts™
on

Hi Folks,

I have a cron entry which suppose to run a script. This is a simple script which only stops and restarts tomcat.I need to do this because the Database sits on different machine and due to weekly schedule reboot of DB box,app lose connection,hence i need to restart the tomcat.
I tried to test my cron entry multiple time yesterday but it failed.

Script:
$more Weeklyrebootscript.sh
#!/bin/bash

echo "App Servers shutting down..."
cd /local/aqueduct/prd/fast/2.11/fcHome
. ./env.sh
mvn fc:service-stop -DserviceNames=tomcatReport03
mvn fc:service-stop -DserviceNames=tomcatnotif02
sleep 120
mvn fc:service-start -DserviceNames=tomcatnotif02
mvn fc:service-start -DserviceNames=tomcatReport03

echo " App being restarted"

i tried it testing yesterday and entry was:
10 10 * * * 4     /local/notif/scripts/Weeklyrebootscript.sh

It failed, and i checked mail and found below error:
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/aqueduct>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=aqueduct>
X-Cron-Env: <USER=aqueduct>
/bin/sh: 4: command not found


Then i changed  first line to #!/bin/sh -x,but still same error.
If i run the script on command line its works fine.

Could you please help how i can get this cronjob working? . Its redhat linux 5.5 (Tikanga).

Thank you
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Correction:


Try
crontab -e
10 10 * * *     /local/notif/scripts/Weeklyrebootscript.sh
Actually for now you can try

* * * * *  /local/notif/scripts/Weeklyrebootscript.sh


There are the following 5 fields and I don't understand why you had 4 there in the first place


           field         allowed values
           -----         --------------
           minute        0-59
           hour          0-23
           day of month  1-31
           month         1-12 (or names, see below)
           day of week   0-7 (0 or 7 is Sun, or use names)
Most Valuable Expert 2013
Top Expert 2013
Commented:
Is "env.sh" actually in /local/aqueduct/prd/fast/2.11/fcHome ?

Where do you set the PATH?
It must contain the location of "mvn", because cron doesn't run shell initialization files, thus you won't have the user's usual environment.

An alternative is calling any binary which is not in /usr/bin or /bin by its full path.

wmp

Author

Commented:
Thank you for your  reply..i just saw my stupid mistake..

10 10 * * * 4     /local/notif/scripts/Weeklyrebootscript.sh

I have an extra * in cron entry.

Thank you farzanj, i had 4 for thur..so i could test it yesterday.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial