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 Previous  1, 2
Author Message
PushedChip649
DD-WRT Novice


Joined: 26 Dec 2012
Posts: 15

PostPosted: Sat Apr 18, 2015 15:25    Post subject: Reply with quote
This is what I did to get my scripts going to populate the crontab.

1- login to router via ssh

2- create a start up script in "Administration>commands"
copy & paste the script below, adjust to your needs and "Save Startup"

#!/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

3- execute the crontab_jobs.sh via Cron job GUI interface, copy and paste the cmd below in "Administration>Management>Additional Cron Jobs
0 11 * * 0-6 root /tmp/root/crontab_jobs.sh

4- validate the CRONTAB jobs where input correctly by the crontab_jobs.sh
# cat /tmp/crontab

0 22 * * 0-4 root /tmp/root/wifi_ath0_off.sh
0 7 * * 0-4 root /tmp/root/wifi_ath0_on.sh
30 00 * * 5,6 root /tmp/root/wifi_ath0_off.sh
0 8 * * 5,6 root /tmp/root/wifi_ath0_on.sh
0 22 * * 0-4 root /tmp/root/wifi_ath1_off.sh
0 10 * * 5,6 root /tmp/root/wifi_ath1_on.sh
30 00 * * 5,6 root /tmp/root/wifi_ath1_off.sh

That's it, I am just going to wait for 00:30 tonight to see if crontab does turn off both my ath.

I will report back.

Issue now is that CRONTAB isn't executing the following scripts;

0 22 * * 0-4 root /tmp/root/wifi_ath0_off.sh
0 7 * * 0-4 root /tmp/root/wifi_ath0_on.sh
30 00 * * 5,6 root /tmp/root/wifi_ath0_off.sh
0 8 * * 5,6 root /tmp/root/wifi_ath0_on.sh
0 22 * * 0-4 root /tmp/root/wifi_ath1_off.sh
0 10 * * 5,6 root /tmp/root/wifi_ath1_on.sh
30 00 * * 5,6 root /tmp/root/wifi_ath1_off.sh

Does anyone know why? A little help would be much appreciated.
Sponsor
plazma
DD-WRT User


Joined: 22 Feb 2012
Posts: 68

PostPosted: Wed Jun 22, 2016 12:40    Post subject: Reply with quote
I found this thread why looking for a solution to schedule the wifi on atheros units.

I know this is the broadcom section, but as PushedChip649 was looking for a solution to make this work on atheros units, i though i would link back to my solution incase other atheros users stumbled over this thread (so broadcom users please forgive me).

Ive posted a working solution to the problem here.
reidun76
DD-WRT Novice


Joined: 19 Jul 2017
Posts: 5

PostPosted: Mon Jul 24, 2017 17:34    Post subject: Reply with quote
Update: I just realized my router is Atheros and these instructions are for Broadcom. Will poke around in the Atheros threads for help there. Thanks!

I am also trying to figure out how to turn wifi on and off on a schedule. I tried the following directions, but it didn't work, and I'm not sure why.

dicksons wrote:
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).


I modified it so it would turn wifi on at 4 every day and turn it off at 11. My code looks like this:

0 16 * * 1,2,3,4,5,6,7 root wl radio off
0 21 * * 1,2,3,4,5,6,7 root wl radio on

Any help would be greatly appreciated!
unisaco
DD-WRT Novice


Joined: 18 Feb 2020
Posts: 1

PostPosted: Tue Feb 18, 2020 8:18    Post subject: Reply with quote
dicksons wrote:
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).


By this way I can turn off radio 2.4G band, but can not for wifi 5G
I tried below code already but not work

0 0 * * 6 root wl0 radio off (I change wl by wl0 but not working, wl only off radio 2.4G)
0 0 * * 1 root wl0 radio on

(My router Linksys ea6500, wifi 5g wl0, wifi 2.4g wl1)
Can anyone teach me ?
Goto page Previous  1, 2 Display posts from previous:    Page 2 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