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

    CRON task not running!

    Scheduled Pinned Locked Moved General pfSense Questions
    13 Posts 3 Posters 1.3k Views 3 Watching
    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.
    • GertjanG Online
      Gertjan @deanfourie
      last edited by

      Put these in a script file, like /root/myscript.sh
      Add nice line like logger "before ..." and end with logger "after ...". Use the the full path of the logger command.
      Don't forget the hash bang with the path to a shell.
      Don't forget to make the script executbale.
      Enter the script as a cron, use the cron pfsense package.

      @deanfourie said in CRON task not running!:

      /sbin/ifconfig hn1 down
      /sbin/ifconfig hn1 up

      When the cron script runs, you see the logger lines in the system log.

      No "help me" PM's please. Use the forum, the community will thank you.
      Edit : and where are the logs ??

      D 1 Reply Last reply Reply Quote 0
      • D Offline
        deanfourie @Gertjan
        last edited by

        @gertjan thanks for the replt.

        sorry I dont understand.

        So something like

        #bash
        logger "enable interface"
        /sbin/ifconfig hn1 up

        and

        #bash
        logger "disable interface"
        /sbin/ifconfig hn1 down.

        Was I even close to on the money HAHA.

        Thanks

        GertjanG 1 Reply Last reply Reply Quote 0
        • GertjanG Online
          Gertjan @deanfourie
          last edited by

          @deanfourie said in CRON task not running!:

          #bash

          No really.
          Use any other shell script file to see what I mrean.
          Is bash installed ? As far as I know, no.

          #!/bin/sh
          

          If bash is installed :

          #!/usr/local/bin/bash
          

          because bash would be here : /usr/local/bin/

          I found logger, it's in in /usr/bin/

          No "help me" PM's please. Use the forum, the community will thank you.
          Edit : and where are the logs ??

          D 1 Reply Last reply Reply Quote 0
          • D Offline
            deanfourie @Gertjan
            last edited by

            @gertjan Sorry man im a little basic when it comes to scripting.

            #!/bin/sh
            /sbin/ifconfig hn1 down

            would take the interface down correct?

            GertjanG 1 Reply Last reply Reply Quote 0
            • GertjanG Online
              Gertjan @deanfourie
              last edited by Gertjan

              @deanfourie said in CRON task not running!:

              would take the interface down correct?

              Yes.
              A command typed on the command line, can also be used in a script file **.

              When I created a text file called /root/test like :

              #!/bin/sh
              /usr/bin/logger "Disable interface"
              /sbin/ifconfig em0 down
              /usr/bin/logger "Enable interface"
              /sbin/ifconfig em0 up
              /usr/bin/logger "Done"
              

              And I make it executable

              chmod +x  /root/test
              

              Now I can

              /root/test
              

              In the system log, I saw :

              5e7d4a57-9d4c-4b52-a392-490ee8a591ea-image.png

              and it broke my connection for a moment, as my WAN interface is em0 for me, it went down and up.

              ** edit : if the command is interactive, things get a bit more complicated.

              No "help me" PM's please. Use the forum, the community will thank you.
              Edit : and where are the logs ??

              D 1 Reply Last reply Reply Quote 0
              • D Offline
                deanfourie @Gertjan
                last edited by

                @gertjan great thank you!

                Then I need to execute the script from the Cron task? How can I call the script?

                Thanks again appreciate your help

                S 1 Reply Last reply Reply Quote 0
                • S Offline
                  SteveITS Rebel Alliance @deanfourie
                  last edited by

                  @deanfourie There is a cron package to manage cron jobs. As I recall if you manually add cron jobs, they are lost on reboot.

                  Only install packages for your version, or risk breaking it. Select your branch in System/Update/Update Settings.
                  When upgrading, allow 10-15 minutes to reboot, or more depending on packages, and device or disk speed.
                  Upvote ๐Ÿ‘ helpful posts!

                  D 1 Reply Last reply Reply Quote 0
                  • D Offline
                    deanfourie @SteveITS
                    last edited by

                    @steveits Yup, CRON package is installed.

                    Only thing I need to get right is to execute the script from the Cron job.

                    GertjanG 1 Reply Last reply Reply Quote 0
                    • GertjanG Online
                      Gertjan @deanfourie
                      last edited by

                      @deanfourie

                      On the main cron page, you have 2 buttons :
                      fa8d6f60-922c-4264-8fe2-78c3a998db3b-image.png

                      018c8a36-fbc7-4b47-bc0b-60d02bd63786-image.png

                      How cron works, what you have to enter as the "time" needs some reading.
                      Any "FreeBSD cron man page" will do here.

                      No "help me" PM's please. Use the forum, the community will thank you.
                      Edit : and where are the logs ??

                      D 1 Reply Last reply Reply Quote 0
                      • D Offline
                        deanfourie @Gertjan
                        last edited by

                        @gertjan Turn out this morning at 11 AM when I was away the interface went down.

                        Turns out I was using 12hour time format not 24hour.

                        FFS

                        So, after all that the CRONs do work.

                        GertjanG 1 Reply Last reply Reply Quote 1
                        • GertjanG Online
                          Gertjan @deanfourie
                          last edited by

                          @deanfourie said in CRON task not running!:

                          Turns out I was using 12hour time format not 24hour.

                          Yes, a day has 24 hours.

                          2e9ba78a-89db-4f8d-ad84-489447a7edd8-image.png

                          No "help me" PM's please. Use the forum, the community will thank you.
                          Edit : and where are the logs ??

                          1 Reply Last reply Reply Quote 0
                          • D Offline
                            deanfourie
                            last edited by

                            @gertjan Thanks for that ๐Ÿ˜›

                            Thanks for your help!

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