What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Cron job example to restart VPN

ASadani

Senior Member
Can anyone help with how to restart astrill, below are the samples I've collected?
how can I add this to the init-start script?

# execute at 4 am daily.

cd /jffs/scripts
/jffs/scripts/init-start
#!/bin/sh
cru a ScheduledVPNRestart "0 4 * * * /dev/astrill/astrillvpn stop"
sleep 5 <<< Will this work?
cru a ScheduledVPNRestart "0 4 * * * /dev/astrill/astrillvpn start"
 
Do all 3 commands in 1 cru job separated by semicolons


Sent from my iPhone using Tapatalk
 
cru a ScheduledVPNRestart "0 4 * * * /dev/astrill/astrillvpn stop;sleep 5;/dev/astrill/astrillvpn start"

You may need to find the path to sleep and prefix it.

This assumes “/dev/astrill/astrillvpn restart” doesn’t work!?



Sent from my iPhone using Tapatalk
 
cru a ScheduledVPNRestart "0 4 * * * /dev/astrill/astrillvpn stop;sleep 5;/dev/astrill/astrillvpn start"

You may need to find the path to sleep and prefix it.

This assumes “/dev/astrill/astrillvpn restart” doesn’t work!?



Sent from my iPhone using Tapatalk
Is the command correct? 04 ***? Do I have to append this command in init or will the cru be sufficient? Can I remove this if needed? sorry for the questions. I'm gonna try it out now.
 
The command I gave needs to go in the init script replacing the 3 line you suggested.

I can’t tell you is 0 4 * * * is correct as you didn’t say what the goal is. This will run the string of 3 commands every 4 am.


Sent from my iPhone using Tapatalk
 
"04 ***" would not be correct because you have removed the spaces. Leave the spaces in as shown by @JDB and the wiki.

Thanks so much. I'm trying vi. Not too good at it but will try. Would have liked an ftp file but this is what I made.
The first lines are from the applet. Do I need to add a colon in the end and fi like the above line?

#!/bin/sh
if [ -e /jffs/astrill/nvram/astrill_bootstrap ]; then eval `cat /jffs/astrill/nvram/astrill_bootstrap`; else eval `nvram get astrill_bootstrap`; fi
cru a ScheduledVPNRestart "0 4 * * * /dev/astrill/astrillvpn stop;sleep 1;/dev/astrill/astrillvpn start"; fi << Is the ; and fi required.
 
"04 ***" would not be correct because you have removed the spaces. Leave the spaces in as shown by @JDB and the wiki.
This is my final file.

#!/bin/sh
if [ -e /jffs/astrill/nvram/astrill_bootstrap ]; then eval `cat /jffs/astrill/nvram/astrill_bootstrap`; else eval `nvram get astrill_bootstrap`; fi
cru a ScheduledVPNRestart "0 4 * * * /dev/astrill/astrillvpn stop;sleep 1;/dev/astrill/astrillvpn start"
 
Sorry, I know nothing about astrillvpn or the commands to make it work.

The line was there earlier. I just added the additional line below it. I'll check in the astrill logs tomorrow to see if the connection has restarted at 4:00 AM. If not then it didn't work. :)
 
If you do a “cru l” then paste the command part it gives you (not the whole line) in and it works; it’ll work at 4am too


Sent from my iPhone using Tapatalk
 
If you do a “cru l” then paste the command part it gives you (not the whole line) in and it works; it’ll work at 4am too


Sent from my iPhone using Tapatalk
I tried this and it didn't restart. I guess it won't work then :(

admin@RT-AC86U-26C8:/tmp/home/root# cru l
0 4 * * * /dev/astrill/astrillvpn stop;sleep 1;/dev/astrill/astrillvpn start #ScheduledVPNRestart#
admin@RT-AC86U-26C8:/tmp/home/root#

I also tried this and got this.

admin@RT-AC86U-26C8:/tmp/home/root# cru l /dev/astrill/astrillvpn stop;sleep 1;/
dev/astrill/astrillvpn start
0 4 * * * /dev/astrill/astrillvpn stop;sleep 1;/dev/astrill/astrillvpn start #ScheduledVPNRestart#
Already connected
admin@RT-AC86U-26C8:/tmp/home/root#
 
Last edited:
You didn’t do as I suggested so no surprise it didn’t restart

You need to copy part of the output cru l gives you back in to test the command [emoji2357]


Sent from my iPhone using Tapatalk
 
You didn’t do as I suggested so no surprise it didn’t restart

You need to copy part of the output cru l gives you back in to test the command [emoji2357]

Sent from my iPhone using Tapatalk

I think I tried that and got the response "already connected"

1st Example of try:
cru l
0 4 * * * /dev/astrill/astrillvpn stop;sleep 1;/dev/astrill/astrillvpn start #ScheduledVPNRestart#
admin@RT-AC86U-26C8:/tmp/home/root#

2nd Example of try:
cru l /dev/astrill/astrillvpn stop;sleep 1;/
dev/astrill/astrillvpn start
0 4 * * * /dev/astrill/astrillvpn stop;sleep 1;/dev/astrill/astrillvpn start #ScheduledVPNRestart#
Already connected
 
Remove the cru l from start of the 2nd attempt

That part is making the stop command fail, so the start gets the already connected response


Sent from my iPhone using Tapatalk
 
Remove the cru l from start of the 2nd attempt

That part is making the stop command fail, so the start gets the already connected response


Sent from my iPhone using Tapatalk

I think it worked, However, I just tried the one in red and not the one in blue which is suffixed in the script. #ScheduledVPNRestart#

admin@RT-AC86U-26C8:/tmp/home/root# /dev/astrill/astrillvpn stop;sleep 1;/dev/astrill/astrillvpn start
Disconnected
Connecting...
admin@RT-AC86U-26C8:/tmp/home/root#

The Actual Script looks like this
#!/bin/sh
if [ -e /jffs/astrill/nvram/astrill_bootstrap ]; then eval `cat /jffs/astrill/nvram/astrill_bootstrap`; else eval `nvram get astrill_bootstrap`; fi
cru a ScheduledVPNRestart "0 4 * * * /dev/astrill/astrillvpn stop;sleep 1;/dev/astrill/astrillvpn start"
 
Last edited:
Remove the cru l from start of the 2nd attempt

That part is making the stop command fail, so the start gets the already connected response


Sent from my iPhone using Tapatalk
Thanks so much for your guidance. I'll revert back tomorrow to let you know if it worked. hopeful :)
 
Pretty sure it will based on the above [emoji106]


Sent from my iPhone using Tapatalk
 
Pretty sure it will based on the above [emoji106]
Sent from my iPhone using Tapatalk

Wanted to confirm that the script successfully executed and the vpn restarted at sharp 4 AM. the restart completed at 4:00 AM and 4 Seconds. Awesome thanks for making this a success.

Thanks to you @JDB and @ColinTaylor
 
Similar threads
Thread starter Title Forum Replies Date
XIYO Questions Regarding acme.sh Cron Job Setup and Directory Linking Asuswrt-Merlin 1

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

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