I know this is a hugely popular type of question so I apologise for that, but I'm truly stuck and I've read through the cron wiki and tried all those suggestions.
I've also tried everything this guy lists in his question, namely:
- adding bash path to crontab
- specifying full path to processes inside bash script
- prefixing the script inside crontab with /bin/bash
- sweating blood since I have a wedding to go to and desperately need this damn script to just work
I can confirm the script works when running from my terminal.
So here goes...
Current crontab:
# add bash to cronjob path
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
# start litecoin daemon on boot
@reboot /opt/litecoin-0.14.2/bin/litecoind
# check every 2 minutes to see if block scrape running and restart it if not
*/2 * * * * /home/grayedfox/github/blockscrape/restartBlockscrape.sh
Script:
#!/bin/bash
NODEPATH=$(which node)
PROCESS="$NODEPATH /home/grayedfox/github/blockscrape/main.js"
if pgrep -f "$PROCESS" > /dev/null; then
echo "Blockscrape is doing it's thing - moving on..."
else
echo "Blockscrape not running! Starting again..."
$PROCESS
fi
I would expect, even if the job fails, to see some sort of error somewhere but I get nothing and see nothing!
Update: I can actually see the cron job being run by checking the /var/log/syslog output.
The output is:
CRON[15038]: (grayedfox) CMD (/home/grayedfox/github/blockscrape/restartBlockscrape.sh)
CRON[15037]: (CRON) info (No MTA installed, discarding output)
The script also sits inside the directory of the node script it calls (although I specify full path as I understand the script, when run by cron, has it's pwd
as $HOME).
echo
statements go, and anything on the standard error stream, will be discarded AFAIKecho
to where? Consider having it log instead.litecoin
on system reboot, that's all./bin/bash -x /home/grayedfox/github/blockscrape/restartBlockscrape.sh > /tmp/log.out 2>&1
as the cron command and post the contents of/tmp/log.out
.