Cron job to reset VPN in slot 1

  • ATTENTION! As of November 1, 2020, you are not able to reply to threads 6 months after the thread is opened if there are more than 500 posts in the thread.
    Threads will not be locked, so posts may still be edited by their authors.
    Just start a new thread on the topic to post if you get an error message when trying to reply to a thread.

Viktor Jaep

Regular Contributor
Hi All,

I'll admit... I'm just not good at this scripting stuff... but what I am looking for is your help/advice on what it would take to automatedly run a cron job at a specific time each night to simply stop/start or restart the VPN client in slot/instance #1.

I figured out that the cron script piece would need to say: 0 01 * * 1-7 -- executing at 01:00 every day of the week... but I'm not sure what script (if any) relating to VPN slot #1 I could execute in order for this to happen, or if it would need to be created?

I appreciate your help, and I appreciate the learning opportunity here! Thank you in advance...
 

ColinTaylor

Part of the Furniture
Using "1-7" for days is non-standard and therefore bad practice. days should range from 0 to 6, but as you want "all days" you might as well use "*" instead.

I can't help you with the VPN command though. :(
 

ColinTaylor

Part of the Furniture
LOL.. thanks! So much for being proactive and using the Crontab expression editor! :)
Ha! I've been doing crontab entries for over 20 years. It's burnt into my brain. :) (To be fair that website does say in red that your command was "Non standard! May not work with every cron." )
 
Last edited:

ColinTaylor

Part of the Furniture
Does this do what you want if you enter it from the command line?
Code:
service restart_vpnclient1
 

Viktor Jaep

Regular Contributor
Does this do what you want if you enter it from the command line?
Code:
service restart_vpnclient1
Yes, thanks -- that does the trick! So is it just a matter of running a command like:

0 01 * * * /jffs/scripts/service restart_vpnclient1

??

And this will survive a reboot, right?
 

ColinTaylor

Part of the Furniture
And this will survive a reboot, right?
No you have to use the cru command and put it in a user script.

Add the following line to the end of your /jffs/scripts/services-start script (assuming it already exists).
Code:
cru a vpn1 "00 01 * * * service restart_vpnclient1"
 

Viktor Jaep

Regular Contributor
No you have to use the cru command and put it in a user script.

Add the following line to the end of your /jffs/scripts/services-start script (assuming it already exists).
Code:
cru a vpn1 "00 01 * * * service restart_vpnclient1"
Thanks a bunch, Colin! That was super helpful! Learned all about how VI is very unuserfriendly, and how nano was much easier to edit files with too... ;) I really appreciate this... will check the logs tomorrow AM and see how it fared!
 

ColinTaylor

Part of the Furniture
BTW you do have to reboot the router for that services-start script to run. ;)
 

Viktor Jaep

Regular Contributor
BTW you do have to reboot the router for that services-start script to run. ;)
Ahh. I was trying to figure out why nothing happened at 1am according to the logs... ;) Good call... it's been rebooted now... let's see what happens tomorrow!
 

ColinTaylor

Part of the Furniture
You can check that the services-start has run correctly by looking at the router's crontab. Enter the following command and you should see your entry:
Code:
cru l
(That's a lower case letter "L" not a number "1")
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top