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

    Cannot get cronjob to work - scripts work when entred manually into shell

    Scheduled Pinned Locked Moved pfSense Packages
    15 Posts 3 Posters 5.5k 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.
    • marcellocM
      marcelloc
      last edited by

      @bigbudd911:

      When you say the full path, are you refering to INSIDE the script? ex.

      Yes.  :)

      Treinamentos de Elite: http://sys-squad.com

      Help a community developer! ;D

      1 Reply Last reply Reply Quote 0
      • B
        bigbudd911
        last edited by

        Awesome. Thank you guys so much!

        1 Reply Last reply Reply Quote 0
        • B
          bigbudd911
          last edited by

          Okay so I just got rid of the last two, to make testing easier.

          I have used the following as my script1.sh  :

          #!/bin/sh
          /sbin/ifconfig ovpnc1  | /usr/bin/grep "inet " | /usr/bin/cut -d\  -f2|/usr/bin/tee /tmp/vpn_ip

          i have tried also putting in a space after the | in between /usr/bin/tee - with no avail. Any idea gents?

          Thank you very much!

          1 Reply Last reply Reply Quote 0
          • P
            phil.davis
            last edited by

            This works for me in cron:

            #!/bin/sh
            /sbin/ifconfig ovpnc1 | /usr/bin/grep "inet" | /usr/bin/cut -f2 -d " " > /tmp/zzz.txt
            

            I guess the "tee" utility does not work so well in a background job? Or maybe the "-d" did something odd?

            As the Greek philosopher Isosceles used to say, "There are 3 sides to every triangle."
            If I helped you, then help someone else - buy someone a gift from the INF catalog http://secure.inf.org/gifts/usd/

            1 Reply Last reply Reply Quote 0
            • B
              bigbudd911
              last edited by

              Thanks very much Phil. I was starting to think that
              maybe it was having difficulty with one of the commands.
              I will give that a shot tonight when I get home from school.
              And just verifying, the command you enter in CRON is just
              to start the script, correct?

              ex.
              1  *  *  *  *  root  /usr/bin/nice -n20 /etc/script1

              OR do you put the actual shell command into the CRON entry?
              (I dont think you do?). Sorry for all the newbish questions guys.

              Once I get this working, I am going to make a tutorial for getting
              this setup entirely, as we have a lot of inexperienced users over
              at my VPN providers boards trying to accomplish the same thing
              I am. Thanks for all the help guys, you are too kind!

              1 Reply Last reply Reply Quote 0
              • B
                bigbudd911
                last edited by

                think i may have found the error. on the tee line, i believe i need a " . "

                /usr/bin/tee ./tmp/vpn_ip

                1 Reply Last reply Reply Quote 0
                • marcellocM
                  marcelloc
                  last edited by

                  @bigbudd911:

                  /usr/bin/tee ./tmp/vpn_ip

                  why you need tee as it is running via cron?

                  did you tried to just redirect to your log file?

                  Treinamentos de Elite: http://sys-squad.com

                  Help a community developer! ;D

                  1 Reply Last reply Reply Quote 0
                  • B
                    bigbudd911
                    last edited by

                    So I tried editing the script to how you said:

                    #!/bin/sh
                    /sbin/ifconfig ovpnc1 | /usr/bin/grep "inet" | /usr/bin/cut -f2 -d " " > /tmp/zzz.txt

                    this is a script - directory is     /etc/script1.sh

                    the crontab entry looks as follows:

                    1   *   *   *   *   root   /usr/bin/nice -n2 /etc/script1.sh

                    and still a no go. this is driving me crazy haha. I am on pfsense 2.1 beta if that
                    makes a huge difference?

                    also, when i run the command in basic shell that Marcelloc posted, I end up getting two lines,
                    an ipv6 address and the ipv4 on line 2

                    1 Reply Last reply Reply Quote 0
                    • P
                      phil.davis
                      last edited by

                      I created /etc/script1.sh containing:

                      #!/bin/sh
                      /sbin/ifconfig ovpnc1 | /usr/bin/grep "inet" | /usr/bin/cut -f2 -d " " > /tmp/zzz.txt
                      

                      Then allow execute and everything on it (you can be more restrictive - this is for testing!):

                      chmod 777 /etc/script1.sh
                      

                      Then add to cron:

                      */1  	*  	*  	*  	*  	root  	/usr/bin/nice -n20 /etc/script1.sh
                      

                      "*/1" runs it every minute. Your setting of "1" in minutes will run it only at 1 minute past each hour.

                      On 2.1 there is IPv6. The OpenVPN gets an IPv6 "fe80:" address as well as IPv4. The output of /sbin/ifconfig contains lines for "inet" and "inet6", which both match your grep. The easy fix is to do

                      /usr/bin/grep -w "inet"
                      

                      then it will match the word "inet" and not the word "inet6".

                      As the Greek philosopher Isosceles used to say, "There are 3 sides to every triangle."
                      If I helped you, then help someone else - buy someone a gift from the INF catalog http://secure.inf.org/gifts/usd/

                      1 Reply Last reply Reply Quote 0
                      • B
                        bigbudd911
                        last edited by

                        Thank you so much Phil for being patient with me.
                        I know it sucks answering super noobish stuff. I really do
                        appreciate it. I was totally unaware of the */1 as well,
                        so that is a big help. :D Will try again tonight, or maybe if
                        I can find an old PC in my computer class, I will give it a try
                        shortly.

                        1 Reply Last reply Reply Quote 0
                        • B
                          bigbudd911
                          last edited by

                          Alright!! Phil you were correct. That worked for the first script. The second one I managed to get working (somehow with the tee command). I ended up using:

                          #!/bin/sh
                          /usr/local/bin/curl ifconfig.me/ip|tee /tmp/vpn_external

                          Now I am on to the final command, I have tinkered with it for about 2 hours, and I can get it to output a file, but the file only contains  {}  , usually it would have the port inside the brackets, ex. {45000}. Currently I am using the following command (the X's represent my username and password. If I enter the command into shell, it does work) I tried using the full path to both cat commands (and without) but no go:

                          #!/bin/sh
                          /usr/local/bin/curl -o /tmp/portforwardlist -d "user=XXXXX&pass=XXXXX&client_id=$(/bin/cat ~/.pia_config)&local_ip=$(/bin/cat /tmp/vpn_ip)" https://www.privateinternetaccess.com/vpninfo/port_forward_assignment

                          ALMOST THERE

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