How to use cron to restart a service every 30 mins?

i need 1 service to restart every 30 minutes, how can i use cron to do that? (rookie question)

i think it can be used using cron in >local startup


# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

exit 0

but i do not know how can someone guide me throught this?

Try the wiki?

*/30 * * * * /etc/init.d/my service restart

1 Like

Aside from the mechanics of doing this, the question I have would be why? If there is some stability issue, it's best to find the root-cause rather than just rebooting (which masks the problem, but doesn't fix it).

So, what is the reason you need to restart the service?

1 Like

just need to restart a service every certain time, like an scheduled task

it worked, thanks

Wouldn't this only do 30 minutes past the hour every hour?
Your options are either
*/30 or 0,30

1 Like

Correct.

30 * * * * Every 30 minutes past every hour on every day.

*/30 * * * * Every consecutive 30 minutes past every hour on every day.

0,30 * * * * At the hour and every 30 minutes past every hour on every day.

so if i want to restart stubby every 30 minutes just do

*/30 * * * * /etc/init.d/service stubby restart ?

1 Like

Yes. When cron starts, this will restart stubby every 30 minutes ie. if cron is enabled/started at 04:10, it will run first at 04:40 then every 30 minutes after.

0,30 * * * * /etc/init.d/service stubby restart would run first at 05:00 then every 30 minutes after.

You can use logread -e cron to see when each cron job runs in syslog.

1 Like

logread -e cron does nothing

just to clarify

this goes in, system > startup > local startup, right?

*/30 * * * * /etc/init.d/service stubby restart

Put it in /etc/crontabs/root
First time you will need to issue: /etc/init.d/cron enable
Then start cron up: /etc/init.d/cron start
OR
In LuCI: System/Scheduled Tasks
Paste it into the text box and Save
Go back to System/Startup - find cron and make sure it’s enabled then restart.

Now when you issue a logread -e cron you’ll see the syslog entries for cron.

1 Like

it shows cron.err started log level 3 , is there an error or is in purpose?

safe to ignore (as long as your cron job is working as expected):

1 Like

thanks everyone @psherman @RuralRoots @lantis1008

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