[Resolved] Crontab task not running.
-
Hello Everyone,
I am trying hard to make a script to run under crontab but for some reason, it doesn't work.Here the crontab entry (using GUI)
1 * * * * root /usr/bin/nice -n20 /etc/LCDmonitor.sh
and here the script:
-rwxr-xr-x 1 root wheel 1277 May 10 18:28 /etc/LCDmonitor.sh
#!/usr/bin/env sh # Cheking if LCDd daemon service is installed. if [ ! -d /usr/local/share/pfSense-pkg-LCDproc ]; then { echo "Service not installed"; exit; } fi #Checking if LCDd Daemon service is Running if [ ! `/bin/pgrep -x "LCDd"` ]; then echo "LCD Daemon is not running - Start it from GUI"; exit else echo "The LCDd Daemon is running" fi # Checking if we have duplicated client processes NOP=`/bin/ps -ax | /usr/bin/grep -I lcdproc_client.php | /usr/bin/grep -v "grep" |wc -l` # If there are more than 1 process, then print message if [ $NOP -gt 1 ] ; then echo "More than 1 process is running - Killing Processes and restarting the service"; /bin/ps -A | /usr/bin/grep lcdproc_client.php | /usr/bin/grep -v "grep" | /usr/bin/awk '{print $1}' | /usr/bin/xargs kill -9 $1 /bin/sleep 2 #Restating the LCDd client /usr/local/bin/php -f /usr/local/pkg/lcdproc_client.php & fi # If there is no client started, We start a single one. if [ $NOP -eq 0 ] ; then echo "No client process is running - Starting one"; #Starting the LCDd client /usr/local/bin/php -f /usr/local/pkg/lcdproc_client.php & echo "A single LCDd client was started" fi # If there is a single client process then print message if [ $NOP -eq 1 ] ; then echo "OK - A single client process is running"; fi
Everything works fine using the Shell, but not under cron.
I have checked an re-checked the paths for the commands. Just don't know what to do anymore.Any help is very welcome!
Thanks
Fabricio. -
Try running your script from /usr/local/bin instead of /etc. I can get it to work from there with a 1/* for the minute instead of just 1.
-
@KOM hello KOM, ... Nice. that did the trick! Not sure why, but it worked.
Also, I got another issue on my script. I was missing the full path for the wc command.
Thanks!! Appreciate the tip!Fabricio.