Command line vs cron execution



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

    and doing the same through cron like

    0 */4 * * * root /usr/local/etc/rc.d/squid.sh 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

    @cirkit:

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

    Maybe try

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



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

    Does not work…

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

    any other thoughts please...


  • Moderator

    0 */4 * * * root /bin/sh /usr/local/etc/rc.d/squid.sh 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.

    or

    0 */4 * * * root /bin/sh -x /usr/local/etc/rc.d/squid.sh 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