How to schedule cron job for WiFi on/off

Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2  Next
Author Message
Crawley
DD-WRT Novice


Joined: 20 Feb 2007
Posts: 1

PostPosted: Thu Feb 22, 2007 11:53    Post subject: How to schedule cron job for WiFi on/off Reply with quote
Hi all,

I have a very simple problem but can't seem to get it right.

I'd like to switch on/off the radio at certain times via cron, e.g. switch it off while I'm at work and while I'm asleep.

In which files do I need to place what cron line with the "wl radio off" command to switch the radio off, say, each day at 1am?

Thanks for the info,
Carsten.
Sponsor
sufrano63
DD-WRT User


Joined: 06 Jun 2006
Posts: 488

PostPosted: Thu Feb 22, 2007 12:26    Post subject: Reply with quote
you can do that using GUI. Look under wireless/advanced section
_________________
блог путешественника
lbaca
DD-WRT Novice


Joined: 05 Oct 2007
Posts: 6

PostPosted: Fri Oct 05, 2007 21:18    Post subject: How to schedule radio on/off differently on weekends Reply with quote
Is there any way to schedule the on/off times of the WiFi radio differently on weekdays and weekends? I know the UI doesn't allow it, but maybe it can be scripted somehow?

Thanks.
infusion
DD-WRT Guru


Joined: 30 Aug 2006
Posts: 506

PostPosted: Fri Oct 05, 2007 23:57    Post subject: Reply with quote
You can't do it in the GUI. But you can do it with cron jobs.
lbaca
DD-WRT Novice


Joined: 05 Oct 2007
Posts: 6

PostPosted: Mon Oct 08, 2007 23:22    Post subject: Reply with quote
@infusion: I've never used cron before; is it exceedingly difficult? Could you give me a nudge in the right direction? If I were to see a script which turns the radio on/off on a particular weekday, I can extrapolate the rest with a little research.

Thanks for answering!
Leandro
infusion
DD-WRT Guru


Joined: 30 Aug 2006
Posts: 506

PostPosted: Tue Oct 09, 2007 4:27    Post subject: Reply with quote
You should use 2 scripts.

wloff.sh
Code:
wl radio off

wlon.sh
Code:
wl radio on


Then, in the startup or the command line (to turn off wireless on saturday and to turn it back on monday):

echo '0 0 * * 6 root /mmc/wloff.sh' >> /tmp/crontab
echo '0 0 * * 1 root /mmc/wlon.sh' >> /tmp/crontab

In the example, the scripts are stored in mmc. You can adapt it for your needs.
Hope it helps.
lbaca
DD-WRT Novice


Joined: 05 Oct 2007
Posts: 6

PostPosted: Tue Oct 09, 2007 16:33    Post subject: Reply with quote
Thank you very much, I'll look into it and let you know!
dicksons
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 980
Location: Coal Creek Canyon, Colorado

PostPosted: Tue Oct 09, 2007 18:13    Post subject: Reply with quote
this is way easy in the gui on v24

go to the admin /management tab

under cron, click "enabled"

under "additonal cron jobs" enter your jobs

to follow infusion's example

0 0 * * 6 root wl radio off
0 0 * * 1 root wl radio on

click "apply" then "reboot router"

that's IT !


(FYI what this does is store the commands in an nvram variable named cron_jobs, which gets written to /tmp/cron.d/cron_jobs at startup).

_________________
linksys GSv2, Gv4, Gv2, GLv1, G-TM, Buffalo wbr2, whr, whr-hp, whr-g125, wli-tx4-g54hp, Moto wr850gp, Alix.3C2
lbaca
DD-WRT Novice


Joined: 05 Oct 2007
Posts: 6

PostPosted: Tue Oct 09, 2007 21:52    Post subject: cron unravelled (?) Reply with quote
If I researched cron correctly, this is what I'm going to use (I'll try it tonight or tomorrow):

echo '0 3 * * 0,6 root /mmc/wloff.sh' >> /tmp/crontab
echo '0 9 * * 0,6 root /mmc/wlon.sh' >> /tmp/crontab
echo '0 2 * * 1,2,3,4,5 root /mmc/wloff.sh' >> /tmp/crontab
echo '0 7 * * 1,2,3,4,5 root /mmc/wlon.sh' >> /tmp/crontab
echo '0 10 * * 1,2,3,4,5 root /mmc/wloff.sh' >> /tmp/crontab
echo '0 19 * * 1,2,3,4,5 root /mmc/wlon.sh' >> /tmp/crontab

This is to have WiFi disabled Saturday and Sunday from 3 AM to 9 AM (when I'm sure to be out of it), and on weekdays from 2 AM to 7 AM (ditto) and from 10 AM to 7 PM (when I'm at work). I suppose home office days and holidays will be a problem, but I'll try to figure something out.

Thanks, guys!
Leandro
dicksons
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 980
Location: Coal Creek Canyon, Colorado

PostPosted: Tue Oct 09, 2007 22:12    Post subject: Reply with quote
Leandro


Here's your jobs in the GUI on the administration \management tab :


just enable, enter jobs, apply, reboot



cron gui.GIF
 Description:
Yes it's really that easy !
 Filesize:  9.92 KB
 Viewed:  73580 Time(s)

cron gui.GIF



_________________
linksys GSv2, Gv4, Gv2, GLv1, G-TM, Buffalo wbr2, whr, whr-hp, whr-g125, wli-tx4-g54hp, Moto wr850gp, Alix.3C2
dicksons
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 980
Location: Coal Creek Canyon, Colorado

PostPosted: Tue Oct 09, 2007 22:23    Post subject: Reply with quote
Leandro --

You can also use the front button on your router (if you have one) to toggle the radio on/off outside of your cron schedule

that's done on the services page

you need to select and apply, and probably reboot,



toggle.GIF
 Description:
 Filesize:  9.15 KB
 Viewed:  73576 Time(s)

toggle.GIF



_________________
linksys GSv2, Gv4, Gv2, GLv1, G-TM, Buffalo wbr2, whr, whr-hp, whr-g125, wli-tx4-g54hp, Moto wr850gp, Alix.3C2
infusion
DD-WRT Guru


Joined: 30 Aug 2006
Posts: 506

PostPosted: Wed Oct 10, 2007 2:17    Post subject: Reply with quote
Thanksfor the tip dicksons.
I think your way is the best way to do it. Very Happy
lbaca
DD-WRT Novice


Joined: 05 Oct 2007
Posts: 6

PostPosted: Wed Oct 10, 2007 2:36    Post subject: Reply with quote
Thanks, dicksons, that seems like the easiest way. However, I'm still on v23, and I don't have those options. However, I added it to the firewall script (I read that the startup script was broken in this version), and it gets added OK to crontab.

Too lazy to test now, so I'll just wait until the specified timeframe to see if it turns off.
lbaca
DD-WRT Novice


Joined: 05 Oct 2007
Posts: 6

PostPosted: Fri Oct 12, 2007 11:23    Post subject: Not working Reply with quote
Hey, guys. Based on the "cron" post on the Wiki, I added "stopservice cron && startservice cron" to the script. The script seems to be working, because the /tmp/crontab file has all my added lines. However, the radio isn't getting turned on/off ever. What am I missing? Am I using the wrong crontab file?

Thanks.
Leandro
PushedChip649
DD-WRT Novice


Joined: 26 Dec 2012
Posts: 15

PostPosted: Mon Apr 06, 2015 0:08    Post subject: Help with last part! Reply with quote
Hello all,

I need some assistance with my startup script.

All cmds are running just fine but not the last one, it doesn't want to run the last sector "Execute input CRONTAB jobs", what am I missing???

Here is the script, very basic but it will do what I need it to do as the GUI cron bugs if I enter more then 3 lines!

#!/bin/sh

###Create ON OFF scripts###
touch /tmp/root/wifi_ath0_off.sh
chmod +x /tmp/root/wifi_ath0_off.sh
echo "#!/bin/sh" > /tmp/root/wifi_ath0_off.sh
echo /sbin/ifconfig ath0 down >> /tmp/root/wifi_ath0_off.sh

touch /tmp/root/wifi_ath0_on.sh
chmod +x /tmp/root/wifi_ath0_on.sh
echo "#!/bin/sh" > /tmp/root/wifi_ath0_on.sh
echo /sbin/ifconfig ath0 up >> /tmp/root/wifi_ath0_on.sh
echo /sbin/reboot >> /tmp/root/wifi_ath0_on.sh

touch /tmp/root/wifi_ath1_off.sh
chmod +x /tmp/root/wifi_ath1_off.sh
echo "#!/bin/sh" > /tmp/root/wifi_ath1_off.sh
echo /sbin/ifconfig ath1 down >> /tmp/root/wifi_ath1_off.sh

touch /tmp/root/wifi_ath1_on.sh
chmod +x /tmp/root/wifi_ath1_on.sh
echo "#!/bin/sh" > /tmp/root/wifi_ath1_on.sh
echo /sbin/ifconfig ath1 up >> /tmp/root/wifi_ath1_on.sh
echo /sbin/reboot >> /tmp/root/wifi_ath1_on.sh

###Create CRONTAB script###
touch /tmp/root/crontab_jobs.sh
chmod +x /tmp/root/crontab_jobs.sh
echo "#!/bin/sh" > /tmp/root/crontab_jobs.sh
echo "echo '0 22 * * 0-4 root /tmp/root/wifi_ath0_off.sh' >> /tmp/crontab" >> /tmp/root/crontab_jobs.sh
echo "echo '0 7 * * 0-4 root /tmp/root/wifi_ath0_on.sh' >> /tmp/crontab" >> /tmp/root/crontab_jobs.sh
echo "echo '30 00 * * 5,6 root /tmp/root/wifi_ath0_off.sh' >> /tmp/crontab" >> /tmp/root/crontab_jobs.sh
echo "echo '0 8 * * 5,6 root /tmp/root/wifi_ath0_on.sh' >> /tmp/crontab" >> /tmp/root/crontab_jobs.sh
echo "echo '0 22 * * 0-4 root /tmp/root/wifi_ath1_off.sh' >> /tmp/crontab" >> /tmp/root/crontab_jobs.sh
echo "echo '0 10 * * 5,6 root /tmp/root/wifi_ath1_on.sh' >> /tmp/crontab" >> /tmp/root/crontab_jobs.sh
echo "echo '30 00 * * 5,6 root /tmp/root/wifi_ath1_off.sh' >> /tmp/crontab" >> /tmp/root/crontab_jobs.sh

###Execute input CRONTAB jobs###
/tmp/root/crontab_jobs.sh
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum