Cannot get cronjob to work - scripts work when entred manually into shell
-
Awesome. Thank you guys so much!
-
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_ipi have tried also putting in a space after the | in between /usr/bin/tee - with no avail. Any idea gents?
Thank you very much!
-
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?
-
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/script1OR 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! -
think i may have found the error. on the tee line, i believe i need a " . "
/usr/bin/tee ./tmp/vpn_ip
-
/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?
-
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.txtthis 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 -
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".
-
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. -
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_externalNow 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_assignmentALMOST THERE