My crond job doesn't work as expected, why?
There's a sudo
in your script but are you sure that your current user has the permission to execute /home/q/tools/bin/restart_tomcat.sh
without password authentication?
You should add the script to /etc/sudoers
to allow your current user to execute the script without password, or you can just sudo crontab -e
to run the script as root (and don't forget to delete sudo
in your script if you do so).
If there is any other option, don't sudo in a cron job.
travelcoCheck.sh
will be matched by thegrep travelco
and is not cancelled by thegrep -v grep
, sowc -l
will be at least 1 always. Sorestart_tomcat.sh
will not run.
(As a side note: whether or not your ps
-parsing stack gets caught by ps
is something of a dark art and is full of corner cases and race conditions and generally difficult to get to work right. Stuff like this is why dbus
was invented.)