Cron is a time-based job scheduler in Linux systems which enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. In this example, we'll use cron to control the wireless signal, and set it to turn on only at given time.
DD-WRT is shipped with cron support, but again we'll use our own cron daemon as it's easier for future updates and will save some flash wearing.
- Disable DD-WRT's Cron
From the web interface, Administration > Management, find "Cron" and disable it, then click "Apply Settings"
- Install cron (busybox) service
The cron is provided by busybox and should've been installed. If not, run
opkg install busybox
and create the scheduling file folder:
mkdir /etc/crontabs
Set it to run on startup by creating /opt/etc/init.d/crond with the commands:
source /mnt/root/.profile
kill -9 $(pidof crond)
/opt/usr/sbin/crond
Then run the commands:
chmod a+x /opt/etc/init.d/crond
ln -s /opt/etc/init.d/crond /opt/etc/init.d/S80crond
- Create a script to switch wireless
Now create a file /opt/usr/sbin/wireless-off.sh
#!/bin/sh
/sbin/ifconfig ath0 down
And another one: /opt/usr/sbin/wireless-on.sh
#!/bin/sh
/sbin/ifconfig ath0 up
On VAP enabled routers, additional interfaces like ath0.1, ath0.2...etc. also need to be taken care of:
/sbin/ifconfig ath0.1 downand
/sbin/ifconfig ath0.1 up
The full list of wireless interfaces can be found by running
/sbin/ifconfig
Don't forget the permissions command:
chmod a+x /opt/usr/sbin/wireless-on.sh /opt/usr/sbin/wireless-off.sh
- Edit Cron Scheduler
DD-WRT's wireless scheduling is available only for Broadcom routers(see picture below) but missing from Atheros builds.
However, its not hard to implement this on Atheros routers with the help of cron and the scripts above.
For example, to turn on wireless only from 5pm to 11pm, run
crontab -e, which will bring you the cron job editor. Add two lines like these:
0 17 * * * /opt/usr/sbin/wireless-on.sh
0 23,0-16 * * * /opt/usr/sbin/wireless-off.sh
Save. The wireless-on script will runs only once at 5PM(17:00) but the wireless-off script runs every hour(23:00, 0:00 ... 16:00) to ensure the wireless can still be turned off in case the router is rebooted halfway.
How about turning off wireless only on weekdays?
0 17 * * * /opt/usr/sbin/wireless-on.sh
0 23,0-16 * * 1-4 /opt/usr/sbin/wireless-off.sh
0 0-16 * * 5 /opt/usr/sbin/wireless-off.sh
Refer here for the full instructions about cron.
3 comments:
Running
00 01 * * * root /sbin/ifconfig ath0 down
30 08 * * * root /sbin/ifconfig ath0 up
(turn ath0 down from 01:00 AM to 08:30 AM)
from the Cron window in Administration -> Management tab does this without the entire detour you copied from http://g300nh.blogspot.com/2010/06/wireless-schedule-with-cron-job.html
You're right, the point of this method is an alternative route if you're having issues with the built-in method. Or if you want to minimize re-flashes since changing Cron settings initiates a flash sequence. Cron didn't work in previous Atheros builds of DD-WRT. I switched to OpenWRT since it has better Atheros drivers and is far more flexible, so I haven't been able to keep up-to-date on the changes. I am considering buying a second router so I can play more for this blog.
Also, I don't hide that most posts are re-published. I re-published them here so people could get support since the other poster abandoned his blog.
Post a Comment
Note: Only a member of this blog may post a comment.