Why my crontab doesn't work?

Why my Scheduled Tasks (crontab) does not work?

* 22 * * * /sbin/wifi down
* 6 * * * sleep 70 && touch /etc/banner && reboot
14 6 * * * /sbin/wifi up
15 6 * * * echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
16 6 * * * echo e > /sys/class/net/eth0/queues/rx-0/rps_cpus
17 6 * * * echo 2 > /sys/class/net/eth0/queues/tx-0/xps_cpus
1 Like

Are you sure that you want this to be executed every minute?
Take a look at https://openwrt.org/docs/guide-user/base-system/cron#periodic_reboot for an example for periodic reboot.

2 Likes

I'm using 19.07.3 and have to restart cron every time after saving any changes to my Scheduled Tasks (crontab)

did you run /etc/init.d/cron enable?

1 Like

This will keep rebooting the router for an hour starting at 6 am :slight_smile:

And this will be shutting down wifi every minute for an hour starting at 22:00

So, at 6 am your router starts rebooting for an hour. During that hour, it makes some changes (if lucky) at 6:14 am, 6:15 am, 6:16 am, and 6:17 am. But the router keeps rebooting regardless, so by the time it is done around 7 am, all your changes are lost.

Update the first two lines to start with 0 instead of *.

Wow, thanks.

This may sound stupid, but try adding an empty line at the end of your cron tab. I had problems with this myself in the past, the jobs wouldn't execute. Adding an empty line at the end solved this.

I have not had to do that on non-Openwrt boxes, though. So it seems a bit strange :slight_smile:

0 22 * * * /sbin/wifi down
0 6 * * * sleep 70 && touch /etc/banner && reboot
14 6 * * * /sbin/wifi up
15 6 * * * echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
16 6 * * * echo e > /sys/class/net/eth0/queues/rx-0/rps_cpus
17 6 * * * echo 2 > /sys/class/net/eth0/queues/tx-0/xps_cpus

This variant does not work too on the OpenWrt SNAPSHOT r14267+10-18fbb9aa21
Model: Mikrotik hAP ac2


Why do you need to stop Wi-Fi before reboot and start after?
This should be done automatically.
And the other commands are better to add to the /etc/rc.local.

1 Like

It does not help, look at this screenshot and current time - my wifi is working :frowning:

Probably you should clarify what exactly you want to achieve.

1 Like

Start step-by-step, does this command work being run from command line?

check the logs, is there cron log? (I am not using cron in my router)

With sleep 70 && touch /etc/banner && reboot - all is ok.

 -----------------------------------------------------
 OpenWrt SNAPSHOT, r14267+10-18fbb9aa21
 -----------------------------------------------------
root@mikrotik:~# /sbin/wifi down
'radio1' is disabled
root@mikrotik:~# uci set wireless.radio1.disabled=1
root@mikrotik:~# uci get wireless.radio1.disabled
1
root@mikrotik:~# uci set wireless.radio1.disabled=0
root@mikrotik:~# uci get wireless.radio1.disabled
root@mikrotik:~# uci set wireless.@wifi-iface[1].disabled='1'
root@mikrotik:~# wifi down radio0
root@mikrotik:~# wifi down radio1

with these commands wifi is down

# uci set wireless.@wifi-iface[0].disabled='1'; uci commit wireless; wifi
'radio1' is disabled
'radio1' is disabled

logread -> https://pastebin.com/0ZCC7Bdm

logread -e cron

is empty

dmesg -> https://pastebin.com/hPGm6wZP

I not able to run wifi via wifi up

OK, write in crontab something like: touch /etc/banner && your wifi command, is it OK?

It does not work

Sorry, you've written before, that touch /etc/banner works. I don't understand.

Did you check the date and time stamp of the file /etc/banner

If the timestamp changes and has the correct time of when the crontab executed then crontab is working

2 Likes

@mbo2o's idea was practical:
Try to figure out if it is about

  • crontab at all, or
  • the wifi command there.

You have the crontab process running, and the file seems ok.

Is the anything in the system logs?
Just thinking along the discussion here, where the user's crontab actually contained uncommented comments...

If you have everything ok, there should be something like this in the system log for each cron action:

root@router1:~# logread | grep cron
Sun Sep  6 02:00:00 2020 cron.err crond[1698]: USER root pid 7934 cmd /etc/storeStats.sh

If there are errors, e.g. parse errors, it might be like:

Wed Aug 5 12:19:00 2020 cron.err crond[793]: user root: parse error at **This**
Wed Aug 5 12:19:00 2020 cron.err crond[793]: user root: parse error at **has**
Wed Aug 5 12:19:00 2020 cron.err crond[793]: user root: parse error at **the**
Wed Aug 5 12:19:00 2020 cron.err crond[793]: user root: parse error at **username**
2 Likes