I have an sh script I want called every three hours via cron. The script calls a bunch of node.js scripts and works perfectly when called directly. However, when called via cron, I get a date logged by the sh script but none of the other logs from my node.js scripts (which all log fine when the sh is called directly). Any idea why?
The script is located in an interior directory but I'm using all absolute paths. Please find my code below and more details on the node.js stuff if necessary on Github (NB: the server was recently changed from sh to bash but I don't think this should have any real impact).
Crontab
SHELL=/bin/sh
MAILTO=my@email.com
0 */3 * * * /absolute/path/to/script.sh
script.sh
#!/usr/bin/env sh
node /absolute/path/to/script1.js
node /absolute/path/to/script2.js
node /absolute/path/to/script3.js
LOGFILE=/absolute/path/to/error.log
log(){
message="$@"
echo $message
echo $message >>$LOGFILE
}
log "Cron performed $(date)"