[solved] Cron not executing anything in /etc/crontabs/root

I have written a script that is mapped to a physical button on the router that turns all the LEDs on or off when pressed. The script checks the LED state and then either enables or disables them depending on what the state is when the button is pressed. This works perfectly.

I want this script to run without pressing the button at 22:30 each night to turn all the LEDs off and at 6:00 each morning to turn the LEDs back on.

Here is the contents of /etc/crontabs/root:

30 22 * * * /usr/sbin/ledbutton
0 6 * * * /usr/sbin/ledbutton

Cron is enabled and appears as a running process however none of the commands in the crontab execute.

To test if this was a script issue or cron issue I added */5 * * * * logger crontest to the cron tab and restarted cron. Nothing is written to the system log either even though cron is running as a process.

The router date and time settings are correct. This is not a date/time issue.

Any ideas as to why, despite being an active process, cron is not executing the contents of /etc/crontabs/root ?

The device is running OpenWrt SNAPSHOT r24002-e3559fb445

try to set executable bit for all users:

chmod +x /path/script_name

or restricted to owner:

chmod u+x /path/script_name

You can check if file is executable with:

ls -la /path/script_name

this ledbutton is a script file correct?

Try writing your commands like this:

30 22 * * * sh /usr/sbin/ledbutton.sh
0 6 * * * sh /usr/sbin/ledbutton.sh

How are you editing the crontab? With a text editor, or crontab -e, or via LuCI?

Try running:

echo root >> /etc/crontabs/cron.update

The script is already executable.

The script did not have a .sh extension originally but adding it made no difference.

I have tried editing the root crontab all three ways with the same results. That command made no difference. Nothing is being executed.

please post command:

cat /usr/sbin/ledbutton

As I said in the original post, this does not seem to be an issue with the script. It executes from a button press or the terminal just fine. Nothing in the crontab executes, not even the test I outlined above to spam the system log every 5 minutes.

Here is the script:

root@OpenWRT:~# cat /usr/sbin/ledbutton

while :
cat /etc/config/system | grep -q 'netdev' 
if [ "$?" -eq 0 ]; then
  cp /etc/config/system /etc/config/leds_on && cp /etc/config/leds_off /etc/config/system && /etc/init.d/led restart
  exit 1
  cp /etc/config/leds_on /etc/config/system && /etc/init.d/led restart
  exit 1

How about a quick sanity check:

ps ww | grep cron
ls -l $(command -v crond)
head -vn -0 /etc/crontabs/*
logread -e crond

Looks normal...like every other OpenWRT device I use:

root@OpenWRT:~# ps ww | grep cron
 8199 root      1100 S    /usr/sbin/crond -f -c /etc/crontabs -l 5
 8264 root      1096 S    grep cron
root@OpenWRT:~# ls -l $(command -v crond)
lrwxrwxrwx    1 root     root            17 Sep 23 06:10 /usr/sbin/crond -> ../../bin/busybox
root@OpenWRT:~# head -vn -0 /etc/crontabs/*
==> /etc/crontabs/root <==
30 22 * * * /usr/sbin/ledbutton
0 6 * * * /usr/sbin/ledbutton
*/5 * * * * logger crontest
root@OpenWRT:~# logread -e crond
Mon Sep 25 07:08:10 2023 cron.err crond[1221]: crond (busybox 1.36.1) started, log level 5
Mon Sep 25 14:56:08 2023 cron.err crond[8137]: crond (busybox 1.36.1) started, log level 5
Mon Sep 25 14:56:18 2023 cron.err crond[8199]: crond (busybox 1.36.1) started, log level 5

perhaps it is better to avoid modifying the configuration files every day to prevent wear of the flash

create a script that disables the LEDs for example:

cat led_off 

# Turn off all led
echo 0 > /sys/class/leds/green:power/brightness
echo 0 > /sys/class/leds/red:info/brightness
echo 0 > /sys/class/leds/green:lan/brightness
echo 0 > /sys/class/leds/green:wlan/brightness
echo 0 > /sys/class/leds/amber:info/brightness
echo 0 > /sys/class/leds/green:wan/brightness

and one that instead restores the desired state

cat led_on

# restore led config
/etc/init.d/led restart


Sorry, forgot about:

ls -la /etc/crontabs
1 Like

Thank you for the suggestion. I will consider this going forward. It still doesn't address the overriding issue of Cron not executing anything in /etc/crontabs/root

root@OpenWRT:/# ls -la /etc/crontabs
drwxr-xr-x    1 root     root             0 Sep 25 14:57 .
drwxr-xr-x    1 root     root             0 Sep 25 15:01 ..
-rwxr-xr-x    1 1000     1000           257 Sep 25 14:56 root


chown root:root /etc/crontabs/root
chmod 600 /etc/crontabs/root
echo root >> /etc/crontabs/cron.update

please exec this command

chown root.root /etc/crontabs/root
chmod 644 /etc/crontabs/root
echo "* * * * * touch /tmp/file-123" >> /etc/crontabs/root
/etc/init.d/cron restart

after a minute it should have created the file, check if it exists

otherwise there is something blocking the cron daemon

which device is it?

does it work with 23.05rc3 from https://firmware-selector.openwrt.org ?

This seems like the fix!

Was this file copied to the router originally, or included in a custom build image?

1 Like