Cron doesn't work properly

Hi,
I have OpenWRT 19.07.7 installed on my AR150 router. I have crond running, but when I modify the crontab file (either via terminal or LuCI/Scheduled Tasks), crond doesn't notice it and doesn't apply the changes until I restart crond manually. Is that a bug, or may I start crond somehow different to notify the modification? Thank you

root@OpenWrt:~# ps |grep cron
 1150 root      1212 S    /usr/sbin/crond -f -c /etc/crontabs -l 5
 1966 root      1208 S    grep cron
root@OpenWrt:~# cat /etc/crontabs/root
* * * * * touch /root/test.file

# EOF
2 Likes

Luci says:

Scheduled Tasks
This is the system crontab in which scheduled tasks can be defined.
Note: you need to manually restart the cron service if the crontab file was empty before editing.

So once the crontab is no longer empty, changes should be recognized automatically.

3 Likes

Yes, that's the thing. It should recognize but it doesn't. The file isn't empty, I add a new line or modify something, and nothing happens.

Yeah, I would like to use the LuCI interface, and I don't want to restart crond always. According to crond's manual, it should check the changes every minute and apply if it's needed.

OpenWrt cron implementation is a stripped off version provided by BusyBox.

i tried to install cron with opkg and it's the same

and as Stefan said, according to LuCI, it shouldn't be restarted once the file is no longer empty, even with the stripped off version

Looking at the current sources it seems to be a copy & paste glitch ... the current JS implementation (https://github.com/openwrt/luci/blob/d61a1c1241b4323e60ad7f9724e97e5871ce96ae/modules/luci-mod-system/htdocs/luci-static/resources/view/system/crontab.js) doesn't include a cron restart afterwards.

Bottomline @vgaetera is right - you need a restart.

1 Like

Hmmmm, okey. Do you know how to add a cron restart command to the JS code, when I click to the Save button?

There's a restart under System->Startup, probably easier to just go there.

I know, but I would like to modify cron regularly. Not only me, but others who prefers one click apply instead of browsing different pages and always search cron in the list to restart it. I think, Scheduled Task originally supposed to work like this, Save&Apply.

Well, you could try to steal the code from the system startup page, and incorporate it into the cron page.

Not as good as save & apply, but at least on the same page.

I think I'll write a shell script with inotifywait which restarts crond if crontab file changes. Not the most elegant, but what to do...

Here is my solution, working well for me:

opkg update && opkg install inotifywait

create the file /etc/init.d/crontab-watcher

#!/bin/sh /etc/rc.common

START=10
STOP=15

start() {
	if [ ! -f /etc/crontabs/root ]; then
        	touch /etc/crontabs/root
	fi
	(while inotifywait -qqe close_write /etc/crontabs/root
        	do /etc/init.d/cron restart
	done) &
}

stop() {
        killall -q inotifywait
}

Enable autostart at boot and start the daemon:

/etc/init.d/crontab-watcher enable
/etc/init.d/crontab-watcher start

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.