Forums

stassen
stassen
Offline
Resolved
0 votes
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...
Sunday, October 24 2021, 06:29 PM
Share this post:
Responses (11)
  • Accepted Answer

    Monday, October 25 2021, 06:01 PM - #Permalink
    Resolved
    0 votes
    The "source /etc/profile" solution also looked interesting but source is not a sh command. More universal appears to be:
    . /etc/profile
    ref - https://stackoverflow.com/questions/4732200/replacement-for-source-in-sh.
    The reply is currently minimized Show
  • Accepted Answer

    stassen
    stassen
    Offline
    Monday, October 25 2021, 05:54 PM - #Permalink
    Resolved
    0 votes
    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.
    The reply is currently minimized Show
  • Accepted Answer

    Monday, October 25 2021, 05:49 PM - #Permalink
    Resolved
    0 votes
    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.
    The reply is currently minimized Show
  • Accepted Answer

    stassen
    stassen
    Offline
    Monday, October 25 2021, 05:32 PM - #Permalink
    Resolved
    0 votes
    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 ;-)
    The reply is currently minimized Show
  • Accepted Answer

    Monday, October 25 2021, 11:59 AM - #Permalink
    Resolved
    0 votes
    Can you try adding the shebang at the beginning of your cronjob as it may be running with sh which I don't think uses "export".
    #! /bin/bash
    The reply is currently minimized Show
  • Accepted Answer

    stassen
    stassen
    Offline
    Monday, October 25 2021, 11:24 AM - #Permalink
    Resolved
    0 votes
    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 ;-)
    The reply is currently minimized Show
  • Accepted Answer

    Monday, October 25 2021, 10:52 AM - #Permalink
    Resolved
    0 votes
    Confused! I expected you to update your crontab job. I've no idea what you've updated or what it will do.
    The reply is currently minimized Show
  • Accepted Answer

    stassen
    stassen
    Offline
    Monday, October 25 2021, 10:08 AM - #Permalink
    Resolved
    0 votes
    Nick Howitt wrote:

    Hmm. I wonder of your sub-commands are not inheriting the PATH. Can you try changing the path line to:
    export PATH=/sbin:/bin:/usr/sbin:/usr/bin
    I am more used to setting the shell with a shebang:
    #! /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 ?
    The reply is currently minimized Show
  • Accepted Answer

    Monday, October 25 2021, 09:33 AM - #Permalink
    Resolved
    0 votes
    Hmm. I wonder of your sub-commands are not inheriting the PATH. Can you try changing the path line to:
    export PATH=/sbin:/bin:/usr/sbin:/usr/bin
    I am more used to setting the shell with a shebang:
    #! /bin/bash


    For DDNS, ddclient will run as a service. No need for cron.
    The reply is currently minimized Show
  • Accepted Answer

    stassen
    stassen
    Offline
    Monday, October 25 2021, 09:10 AM - #Permalink
    Resolved
    0 votes
    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!
    The reply is currently minimized Show
  • Accepted Answer

    Sunday, October 24 2021, 06:51 PM - #Permalink
    Resolved
    0 votes
    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.
    The reply is currently minimized Show
Your Reply