Sunday, June 27, 2010

Wireless Scheduler with Cron Job

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, 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 update and will save some flash wearing.

  1. Disable DD-WRT's Cron
    From the web interface, Administration->Management, find "Cron" and disable it, then click "Apply Settings"

  2. 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 following:

    source /mnt/root/.profile
    kill -9 $(pidof crond)

    chmod a+x /opt/etc/init.d/crond
    ln -s /opt/etc/init.d/crond /opt/etc/init.d/S80crond

  3. The script to switch wireless
    Now create a file /opt/usr/sbin/

    /sbin/ifconfig ath0 down

    another one: /opt/usr/sbin/

    /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 down
    /sbin/ifconfig ath0.1 up
    The full list of wireless interfaces can be found by running /sbin/ifconfig

    Don't forget the permission:
    chmod a+x /opt/usr/sbin/ /opt/usr/sbin/

  4. 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 that

    0 17 * * *   /opt/usr/sbin/
    0 23,0-16 * * *   /opt/usr/sbin/

    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.

    Now how about turning off wireless only on weekdays?

    0 17 * * *   /opt/usr/sbin/
    0 23,0-16 * * 1-4   /opt/usr/sbin/
    0 0-16 * * 5   /opt/usr/sbin/

    Refer here for the full instruction about cron.


Anonymous said...

Thanks for this posting. I'd been looking for a way to turn the radio on/off based on time of day. Looking at the crontabs I understand the precaution of assuming things don't always go as planned and that perhaps the router might get cycled during its presumed off period. Running the off-script "just in case" is acceptable I suppose but do you know of a way (a script of some sort) to determine within the program if the radio is off or on? Just seems like a cleaner approach than not knowing and continuing to turn the radio off when it is in fact likely already off.

leo.d said...

The router is running openwrt atm so I'm not sure if it's the same on dd-wrt. However, on OpenWrt, when turn off the wireless(ifconfig wlan0 down) the wlan0 interface is no longer displayed in "ifconfig" output, also the output of "ifconfig wlan0" is slightly different from when wifi is on.

Anonymous said...


if i try to create the scheduling file folder i get this error message:

mkdir: cannot create directory '/etc/crontabs': Read-only file system

how can i fix this ?

Anonymous said...

I am unable to create the folders you are refering to in the guide. nothing happends. when I do df -h I can see that 100% (4,1 MB) of my filesystem is in use. Is this guide based on routers with external harddrives attaced?

Anonymous said...

To all who receive errors: Seems that commands only work with "real official" DD-wrt, not Buffalo branded.

Another thing, I think there is a typo, opkg should be ipkg?

Gianluigi Di Vaio said...

Hi, from my point of view is much better to go in Administration -> Management and enable the cron daemon, than in the "cron window" write something like this example:
30 23 * * * root /sbin/ifconfig ath0 down
30 06 * * * root /sbin/ifconfig ath0 up

The example script will shutdown the WiFi at 23.30 everyday and will start-up it again at 06.30

Remember to Apply and Reboot your DD-WRT router!

Koen De Jaeger said...

Does this also turn off the radio waves that are emitted by the router and cause long term health problems?

Anonymous said...

Thank you to Gianluigi Di Vaio for his tips ;)

Unknown said...

Ciao Gianluigi Di Vaio.. visto che sei italiano potresti aiutarmi?
Io possiedo questo router TP-Link WR1043ND e avrei la necessità di spegnere ed accendere in automatico la WiFi.
Vorrei farlo con il cron, ma non riesco a capire il giusto script da scrivere.
Io vorrei accendere la wirelessa ogni giorno alle 6:00 del mattino e spegnerla ogni giorno alle 21:00
Qualcuno può dirmi cosa devo scrivere dentro il CRON JOB (giusti spazi...root, etc)?

Unknown said...

The built in cron cant be disabled. It gets enabled when I reboot and then prevents the cron from busybox from starting!

RouterLogin said...

Thank you for sharing valuable information
Router Login not working
routerlogin admin page
Routerlogin Net

Robert Green said...

It is one of the best site that I have visited. Hope you will share more quality blog posts thank you.
Quickbooks contact helps you with everything regarding QuickBooks software. If you are stuck in some general issues related to QuickBooks like installation error or payroll issues then we are here to help you anytime you want.

shalley30 said...

Nice blog post on this topic.Gmail Customer Service Number
Gmail support number

AllHelplineNumber said...

We are one of the third party which provide best in class support for all kind of Roku tv setup , installation, updation and much more related issues over phone call and chat across the USA 24*7. We have a dedicated team of professionals who are well certified and experience to handle all kind of Roku tv box issues. We ensure each and every customer to get full satisfaction for his concern. You just need to dial up our roku customer support service number 1-800-382-3046.
Roku Customer Service Number
Roku Support Phone Number
Roku Toll Free Number
Roku Customer Care Number
Roku Helpline Number

Candice Cromwell said...
This comment has been removed by the author.
Candice Cromwell said...
This comment has been removed by the author.
Candice Cromwell said...
This comment has been removed by the author.
shalley30 said...

if you are facing problem related to virus in your PC and computer.Sign in to enter your product key, access your account, manage your subscription, and extend your Norton protection to PC, Mac, Android, and iOS devices then contact us.

Alex williams said...

Do you require HP printer setup for your mac operating system? Is your printer driver not suitable for macOS? Then visit the to get the software and driver for better functioning of your printer. You can also call our expert HP support team for services.

Ida F. Breton said...

telkahost said...

اما ممکن است این سوال به ذهنتان بیاید که یک خرید هاست خرید هاست اشتراکی ارزان ارزان چه هاستی است و چه ویژگی هایی باید دارا باشد در ادامه مقاله قصد داریم ویژگی های هاست ارزان را خرید هاست لینوکس ماهانه معرفی کنیم و در آخر به معرفی بهترین هاست ایران از میان هاستینگ های برتر کشور بپردازیم .اگر قصد راه اندازی یک سایت باکیفیت و پر بازدید را دارید حتما باید نکته هایی را رعایت نمایید قسمت سخت افزار از انتخاب ها تشکیل می شود و مناسب برای سایت هست که به سرور استفاده شده با هاست ارزان برای وردپرس سی پی یو ، رم و استفاده از دیگر سخت افزارها هاست ارزان خارجی با ویژگی های عنوان شده مربوط می شود .نرم افراز به دو بخش جدا تقسیم می شود که بخشی از آن به هاست و سرور مربوط هست و بخش دیگر به سیستم مدیریت محتوا سایت شما بستگی دارد .و در نهایت بخش محتوا هاست پرسرعت ارزان ارتباط با کار سئو و بهینه سازی سایت برای موتورهای جستجو و هم چنین بازاریابی از طریق محتوا است .در حقیقت هاست یک بستر الکترونیکی هست که محتویات و مطالب سایت شما داخل آن ذخیره خواهد شد .و این محتویات هاست ارزان قیمت همان فایل و دیتابیس شما است که از طریق اتصال اینترنتی کاربران به سرور در دسترس خواهد بود .لازم است که هاست و دامنه به یک دیگر متصل باشند که این فرآیند از طریق Name server صورت می گیرد .بدین ترتیب اولین کاری که بعد از خرید هاست از شرکت های معتبر هاستینگ باید انجام دهید این هست که نیم سرور های هاست را بر روی دامنه خودتان ست کنید تا نهایتا بعد از گذشت ۷۲ ساعت هاست و دامنه به هم دیگر متصل شوند

nighthawkrouterlogin said...

For Netgear Extender solution Kindly read this informative blogs. For Want to Troubleshoot Router Login Access Errors? Read This
More information is available on
WiFi Disconnecting? Fix-it!​
Is Your Router Keeps Dropping Internet?

Support Tech 247 said...

Looking for D-Link Support UK, visit on:

Alwin Joseph said...

It is really very helpful for us and I have gathered some important information from this blog.
123 HP Setup

Ameejames said...

Looking for D-link Support call on 1800987893 , visit on:
D-link router reset
D-link Router Support

Jack said...

Webroot Activate
Mcafee Activate

James Smith said...

Nice post. I was checking continuously this blog and I am impressed! Very helpful information specially the last part :) I care for such info a lot. I was looking for this certain info for a long time. Thank you

Emma watson said...

Interesting blog. It would be great if you can provide more details about it. Thanks you
HP Envy 7855 Printer Setup

James Patrick said...

This post will be very useful to us....i like your blog and helpful to me....nice thoughts for your great work....
HP Envy 5055 Printer Setup

Sumit Kumar said...

Quickbooks error 41

Quickbooks Login error

Quickbooks payroll update

Quickbooks error code 1402

Quickbooks online login error

Anonymous said...

Божественно креативныеда еще невероятно точные онлайн гадания для уточнении загадывания вашего ближайшего будущего: это исключительно то, что вы найдете на страницах нашего сайта. Гадание на отношение человека, на картах является наиболее быстрым и простым вариантом для получения нужных сведений из эмпирического поля Земли.

Post a Comment