Reputation: 13
I have a java service running on a solaris server. I need to kill this service and restart it every night at a specified time. Hence i have set a cron job to do the same. My script works fine when i execute it manually through command line. But when i set it as a cron job, it executes only half way i.e it only kills the process but does not start it. Kindly assist me. Below are the details:
Restart script:
#!/bin/sh
pkill -u peri java 2>> /dev/null
sleep 3
cd /opt/home/peri/utils/jsb
. /opt/home/peri/utils/jsb/pjsb.new
sleep 3
cd /opt/jar
MonitorExt.sh & > /dev/null
Here pkill is killing the java process. The script pjsb.new is the script which is used to start the java process. Also one more script MonitorExt.sh is used to start another java process.
Any help is highly appreaciated!!!! Thanks in advance
Upvotes: 1
Views: 1103
Reputation: 734
1) under user 'root', check for some cron error messages in /var/cron/log
2) usually when commands/scripts are running fine manually but not in the cron job, it is because some environment variables are not set in the cronjob context. So you should make sure that all the necessary environment variables which are automatically set in your default shell ($HOME, $JAVA, ...) are actually set when running in a cron job
I usually call a profile script inside the script or in the cronjob line:
15 17 * * * . $HOME/.profile && $HOME/script.sh
3) You should also prefer full paths for all your scripts and commands:
/usr/bin/pkill
/path/MonitorExt.sh
...
Upvotes: 1