What methods can be used to organize automatic script execution in Linux at a specified time or on a schedule?
sobes.tech AI
Answer from AI
In Linux, the most commonly used tools for automatically running scripts at a specified time or on a schedule are:
-
cron — the most widespread method. Using the command
crontab -e, you can set a schedule for running scripts. The record format includes minutes, hours, days of the month, months, and days of the week.Example of a record to run a script every day at 3:30:
30 3 * * * /path/to/script.sh -
systemd timers — a modern method if systemd is used. It allows creating timers that start services according to a schedule.
-
at — for a one-time task execution at a specified time.
-
Scripts in directories like
/etc/cron.daily/,/etc/cron.hourly/, etc. — for periodic execution without editing crontab.
Thus, for regular tasks, cron is usually used, and for more complex scenarios — systemd timers.