I have something struggle with crontab which I can't resolve. I'm trying to schedule a radio program recording on a weekly basis.
If the script is executed manually by me (root privilege), everything works as expected. If I schedule it in crontab it does not work. Nothing in /var/log/cron, no PID, nothing.
#!/bin/bash
# Record stream and save it
# recordingstart.sh
streamripper http://x.x.x.x:8000 -d "/var/flexshare/shares/vol4/1. Streamrecordings/" -o larger -t --quiet -u "FreeAmp/2.x" &
# End script
Crontab -l
*/30 * * * * /install/script/dyndns.sh
0 16 * * 5 /install/script/recordingstart.sh
0 19 * * 5 /install/script/recordingstop.sh
Other parts of the Crontab are being executed...
If the script is executed manually by me (root privilege), everything works as expected. If I schedule it in crontab it does not work. Nothing in /var/log/cron, no PID, nothing.
#!/bin/bash
# Record stream and save it
# recordingstart.sh
streamripper http://x.x.x.x:8000 -d "/var/flexshare/shares/vol4/1. Streamrecordings/" -o larger -t --quiet -u "FreeAmp/2.x" &
# End script
Crontab -l
*/30 * * * * /install/script/dyndns.sh
0 16 * * 5 /install/script/recordingstart.sh
0 19 * * 5 /install/script/recordingstop.sh
Other parts of the Crontab are being executed...
Share this post:
Responses (11)
-
Accepted Answer
Crontab does not inherit the root PATH so any executable called from crontab needs to either be called using its full path (including paths within sub-scripts) or you need to set the path at the beginning of your crontab file before any executables are called. Have a look at /etc/cron.d/0hourly as an example.
Can I ask what is the /install/script/dyndns.sh doing? Did you know you get a free DDNS name with your ClearOS installation? Also ddclient is a good live DDNS updater if you don't want to use your poweredbyclear.com DDNS name.
Lastly, if you don't want to run from crontab, you can also run your cron jobs from /etc/cron.d just by dropping a file in there. -
Accepted Answer
Nick Howitt wrote:
Crontab does not inherit the root PATH so any executable called from crontab needs to either be called using its full path (including paths within sub-scripts) or you need to set the path at the beginning of your crontab file before any executables are called. Have a look at /etc/cron.d/0hourly as an example.
Can I ask what is the /install/script/dyndns.sh doing? Did you know you get a free DDNS name with your ClearOS installation? Also ddclient is a good live DDNS updater if you don't want to use your poweredbyclear.com DDNS name.
Lastly, if you don't want to run from crontab, you can also run your cron jobs from /etc/cron.d just by dropping a file in there.
In my opinion I'm calling the scripts including a full path. Currently testing an adapted cron including the parameters:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
So my updated crontab looks now like this
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/install/script
MAILTO=root
*/45 * * * * /install/script/duckdnsorg.sh
*/30 * * * * /install/script/dyndns.sh
0 16 * * 5 root /install/script/recordingstart.sh
0 19 * * 5 root /install/script/recordingstop.sh
43 9 * * 1 root /install/script/recordingstart.sh
59 9 * * 1 root /install/script/recordingstop.sh
And the permissions in /install/script
ls -l record*
-rwxrwxrwx 1 root root 193 Oct 24 20:18 recordingstart.sh
-rwxrwxrwx 1 root root 86 Oct 17 14:43 recordingstop.sh
Result -> still not taken into account by cron.
cron.log
Oct 25 09:43:01 stassen CROND[28141]: (root) CMD (root /install/script/recordingstart.sh )
Oct 25 09:45:01 stassen CROND[28275]: (root) CMD (LANG=en_US /usr/clearos/apps/base/deploy/servicewatch >/dev/null 2>&1)
Oct 25 09:45:01 stassen CROND[28276]: (root) CMD (/install/script/duckdnsorg.sh)
Oct 25 09:45:01 stassen CROND[28277]: (root) CMD (/usr/sbin/events-notification -i > /dev/null 2>&1)
Oct 25 09:50:01 stassen CROND[28690]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Oct 25 09:50:01 stassen CROND[28691]: (root) CMD (/usr/sbin/events-notification -i > /dev/null 2>&1)
Oct 25 09:50:01 stassen CROND[28692]: (root) CMD (LANG=en_US /usr/clearos/apps/base/deploy/servicewatch >/dev/null 2>&1)
Oct 25 09:55:01 stassen CROND[29087]: (root) CMD (/usr/sbin/events-notification -i > /dev/null 2>&1)
Oct 25 09:55:01 stassen CROND[29088]: (root) CMD (LANG=en_US /usr/clearos/apps/base/deploy/servicewatch >/dev/null 2>&1)
Oct 25 09:59:01 stassen CROND[29429]: (root) CMD (root /install/script/recordingstop.sh)
To answer your question about dyndns.sh ;-) I'm aware of the DDNS provided by ClearOS but decided to use another provider which can be updated on multiple machines (not only this server) to secure the updates.
I do want to run it from crontab because it is easy to maintain via crontab -e compared to /etc/cron.d.
But I'm very happy to get support and to learn from you (and others) via this forum! -
Accepted Answer
-
Accepted Answer
Nick Howitt wrote:
Hmm. I wonder of your sub-commands are not inheriting the PATH. Can you try changing the path line to:
I am more used to setting the shell with a shebang:export PATH=/sbin:/bin:/usr/sbin:/usr/bin
#! /bin/bash
For DDNS, ddclient will run as a service. No need for cron.
Updated cron and path. New results:
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/install/script
echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/install/script
Crontab
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/install/script
MAILTO=root
*/45 * * * * /install/script/duckdnsorg.sh
*/30 * * * * /install/script/dyndns.sh
0 16 * * 5 root /install/script/recordingstart.sh
0 19 * * 5 root /install/script/recordingstop.sh
0 12 * * 1 root /install/script/recordingstart.sh
10 12 * * 1 root /install/script/recordingstop.sh
ps aux | grep 'streamripper'
root 7724 0.0 0.0 112812 980 pts/0 S+ 12:01 0:00 grep --color=auto streamripper
Cron.log
Oct 25 12:00:01 stassen CROND[7430]: (root) CMD (root /install/script/recordingstart.sh)
Are there additional options to create more details why this is not running or where it stores the content grabbed ? -
Accepted Answer
-
Accepted Answer
Nick Howitt wrote:
Confused! I expected you to update your crontab job. I've no idea what you've updated or what it will do.
In case you wanted to update my cron by
export PATH=/sbin:/bin:/usr/sbin:/usr/bin, I've tried that, but it returned an error on the word 'export' and that is the reason why it is not in my cronjob.
Maybe that explains it better ;-) -
Accepted Answer
-
Accepted Answer
I have success with the following mod to the script when used in crontab.
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/usr/local/bin/streamripper http://x.x.x.x:8000 -d "/var/flexshare/shares/vol4/1. Streamrecordings/" -o larger -t --quiet -u "FreeAmp/2.x
Just learned something again. Would be nice if there was a better way of tracing these issues, but I'm happy that I got result. @Nick: Thanks for supporting me during this process ;-) -
Accepted Answer
Ok so you went for sh and not bash but that is a personal choice. The issue is a known issue with cron/crontab and presumably appears somewhere in its documentation (but is not in "man crontab"). The internet has references like https://stackoverflow.com/questions/2388087/how-to-get-cron-to-call-in-the-correct-paths.
Anyway, it is working now. -
Accepted Answer
Nick Howitt wrote:
Ok so you went for sh and not bash but that is a personal choice. The issue is a known issue with cron/crontab and presumably appears somewhere in its documentation (but is not in "man crontab"). The internet has references like https://stackoverflow.com/questions/2388087/how-to-get-cron-to-call-in-the-correct-paths.
Anyway, it is working now.
I found that article also and is helpful. My solution was adding the full path in the script. Only then it was working. Hopefully someone will run into this solution in the future when running into the same. -
Accepted Answer
The "source /etc/profile" solution also looked interesting but source is not a sh command. More universal appears to be:
ref - https://stackoverflow.com/questions/4732200/replacement-for-source-in-sh.. /etc/profile
Please login to post a reply
You will need to be logged in to be able to post a reply. Login using the form on the right or register an account if you are new here.
Register Here »