Currently I got stuck by trying to execute a shell script via crontab. It does not work and I can't figure out what is wrong here.
What I want to do is: Execute a javascript (index.js) file with nodejs periodically.
The file run-logger.sh
is executable (-rwxr-xr-x
) and located under /home/pi/apps/fritz-client
.
run-logger.sh
:
#!/bin/bash
# execute index.js and save all output to log
/usr/bin/env node /home/pi/apps/fritz-client/index.js >> fritz.log
If I run this command standalone /usr/bin/env node /home/pi/apps/fritz-client/index.js >> fritz.log
everything went fine! Even If I do cd /home/pi/apps/fritz-client && ./run-logger.sh
crontab -e
:
#
# lots of comments
#
*/1 * * * * /home/pi/apps/fritz-client/run-logger.sh
crontab -l
shows it too.
I tried:
*/1 * * * * /home/pi/apps/fritz-client/run-logger.sh
*/1 * * * * /bin/bash /home/pi/apps/fritz-client/run-logger.sh
*/1 * * * * /bin/sh /home/pi/apps/fritz-client/run-logger.sh
*/1 * * * * bash /home/pi/apps/fritz-client/run-logger.sh
The command more /proc/version
results in:
Linux version 4.1.18-v7+ (dc4@dc4-XPS13-9333) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611) ) #846 SMP Thu Feb 25 14:22:53 GMT 2016
Update
This is my first week using linux and a raspberry pi. So be please patient :)
syslog output
Mar 14 21:08:01 raspberrypi CRON[3609]: (pi) CMD (/home/pi/apps/fritz-client/run-logger.sh)
Mar 14 21:08:01 raspberrypi CRON[3602]: (CRON) info (No MTA installed, discarding output)
Mar 14 21:09:01 raspberrypi CRON[3626]: (pi) CMD (/home/pi/apps/fritz-client/run-logger.sh)
Mar 14 21:09:01 raspberrypi CRON[3619]: (CRON) info (No MTA installed, discarding output)
Mar 14 21:10:01 raspberrypi rsyslogd-2007: action 'action 17' suspended, next retry is Mon Mar 14 21:11:31 2016 [try http://www.rsyslog.com/e/2007 ]
Mar 14 21:10:01 raspberrypi CRON[3642]: (pi) CMD (/home/pi/apps/fritz-client/run-logger.sh)
Mar 14 21:10:01 raspberrypi CRON[3635]: (CRON) info (No MTA installed, discarding output)
Mar 14 21:10:06 raspberrypi crontab[3651]: (pi) BEGIN EDIT (pi)
Mar 14 21:10:19 raspberrypi crontab[3651]: (pi) REPLACE (pi)
Mar 14 21:10:19 raspberrypi crontab[3651]: (pi) END EDIT (pi)
ps aux | grep cron
root 382 0.0 0.2 5548 2452 ? Ss 19:01 0:00 /usr/sbin/cron -f
pi 3683 0.0 0.2 4772 1936 pts/0 S+ 21:11 0:00 grep --color=auto cron
stderr
output, which usually gets e-mailed. You can capture it in the same file by adding2>&1
to the command.cd /home/pi/apps/fritz-client && /usr/bin/env node /home/pi/apps/fritz-client/index.js 2>&1 fritz.log
>whatever.log 2>&1