Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Command line vs cron execution

    Scheduled Pinned Locked Moved General pfSense Questions
    5 Posts 2 Posters 1.1k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      cirkit
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • BBcan177B
        BBcan177 Moderator
        last edited by

        @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

        "Experience is something you don't get until just after you need it."

        Website: http://pfBlockerNG.com
        Twitter: @BBcan177  #pfBlockerNG
        Reddit: https://www.reddit.com/r/pfBlockerNG/new/

        1 Reply Last reply Reply Quote 0
        • C
          cirkit
          last edited by

          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...

          1 Reply Last reply Reply Quote 0
          • BBcan177B
            BBcan177 Moderator
            last edited by

            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

            "Experience is something you don't get until just after you need it."

            Website: http://pfBlockerNG.com
            Twitter: @BBcan177  #pfBlockerNG
            Reddit: https://www.reddit.com/r/pfBlockerNG/new/

            1 Reply Last reply Reply Quote 0
            • C
              cirkit
              last edited by

              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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post
              Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.