2

Because vpnc stopped every ~23 hours, I created a .sh file that is running as a cron job every 10 minutes, all that it does, is stop the vpnc process and run it again.

I have made it executable by chmod + x ping_vpnc.sh and it works fine when I run it from the terminal via ./ping_vpnc.sh

My file looks similar to:

#!/bin/sh

killall vpnc #just to make sure I don't create too many tunnels.
vpnc default.conf  #run vpnc connect file.

my crontab file:

*/10 * * * * /home/username/ping_vpnc.sh

the problem with the script that it does't run fully, so it just kill the process without re-running it.

I'm running the script as root so I don't think that it's a privilege issue.

Any idea about why this is happening? I will appreciate it.

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84
mongotop
  • 7,114
  • 14
  • 51
  • 76
  • 1
    I'm not extremely familiar with `vpnc`, but could it be the case that the old process takes a little time to die fully, and the new one notices that the old one is still (partially) there, so it refuses to start? Maybe put a `sleep 1` in between the two or something if that's the case... – twalberg May 06 '13 at 19:18
  • I tried it but it still the same issue, and wehn I run the bash script manually ./ping_vpnc.sh it works as expected! but not on crontab :( – mongotop May 06 '13 at 19:28
  • 1
    Change `* * * ... /home...` for `* * * /bin/sh /home...`, you need to indicate the binary executing the script. – fedorqui May 06 '13 at 19:29
  • I made the change and I have to wait few minutes so the script can run on crontab. your solution seems right and I found something similar here but I didn't understand it until your suggested the solution. `http://askubuntu.com/questions/117978/script-doesnt-run-via-crontab-but-works-fine-standalone/277869#277869` Thanks a lot!!! – mongotop May 06 '13 at 19:33
  • please put your suggestion as solution, it works perfect!!! thank you very much!!! – mongotop May 06 '13 at 20:02

1 Answers1

4

As indicated on comments, change

*/10 * * * * /home/username/ping_vpnc.sh

for

*/10 * * * * /bin/sh /home/username/ping_vpnc.sh

that is, tell crontab which binary has to execute the script.

For future references, let me point out the question you found in Ask Ubuntu: Script doesn't run via crontab but works fine standalone. It provides comprehensive information about the topic.

Community
  • 1
  • 1
fedorqui
  • 275,237
  • 103
  • 548
  • 598