Command line vs cron execution

  • I want to have the same effect of executing /usr/local/etc/rc.d/ restart

    and doing the same through cron like

    0 */4 * * * root /usr/local/etc/rc.d/ restart

    but executing through cron does not work the same way as executing through shell….why?
    and how do I achieve the same effect through cron?

  • Moderator


    0 */4 * * * root /usr/local/etc/rc.d/ restart

    Maybe try

    0 */4 * * * root /bin/sh /usr/local/etc/rc.d/ restart

  • 0 */4 * * * root /bin/sh /usr/local/etc/rc.d/ restart

    Does not work…

    I still cannot rotate logs...i.e.use squid -k until I use from shell

    any other thoughts please...

  • Moderator

    0 */4 * * * root /bin/sh /usr/local/etc/rc.d/ restart > /usr/local/etc/rc.d/debug.txt 2>&1
    This will create a file in that folder ( you can change the path to whatever) and this will create an output file to help debug it.


    0 */4 * * * root /bin/sh -x /usr/local/etc/rc.d/ restart > /usr/local/etc/rc.d/debug.txt 2>&1

  • Both of the above suggested methods do not produce the result of issuing the command manually through CLI, the debug.txt contains no specifics to point to errors or privileges in execution of the script.

    the environment of cron is /var/log while environment of CLI is /root  How to execute cron scripts with /root environment

Log in to reply