cron, alternative Linux à Task Scheduler
Mis à jour le
Notre avis
Cron is a solid replacement for Windows Task Scheduler for users who need to schedule recurring jobs based on time. It covers the core use‑cases of running scripts, binaries, and commands at specific times or intervals, and can operate without a logged‑in user. It is ideal for system administrators, developers, and power users who prefer a text‑based configuration and are comfortable with the crontab syntax. For users who rely heavily on event‑driven triggers or a graphical interface, systemd timers or third‑party tools may be preferable.
- Licence
- GPL-3.0
- Prix
- Gratuit
- Dernière version
- 4.1
- Note
- —
Ce qui fonctionne pareil
- Both schedule tasks to run automatically at specified times or intervals
- Both can execute scripts, binaries, and system commands
- Both support running tasks without a user being logged in
- Both allow redirecting output to files or mail
- Both can be managed per user
Ce qui change
- Cron is purely time‑based; it does not natively trigger on arbitrary system events (e.g., network connection, USB insertion)
- Cron lacks a built‑in graphical UI; configuration is via plain text files
- Cron does not provide a detailed execution log or status view out of the box; logs are written to syslog or mailed
- Cron cannot run tasks based on complex conditions or dependencies between jobs
- Cron does not support running tasks with elevated privileges unless the user’s crontab is edited by root
Ouvrir vos fichiers Task Scheduler
Windows Task Scheduler stores jobs in .job files that are not readable by cron. There is no direct import or export mechanism. To migrate, you must manually translate each scheduled task into a crontab entry, recreating any required environment variables or command wrappers.
Passer de Task Scheduler à cron, étape par étape
- 1. Export the Task Scheduler list to a readable format (e.g., use the Task Scheduler console to view each task’s trigger and action).
- 2. For each task, decide the equivalent cron schedule (minute, hour, day, month, weekday).
- 3. Open the user’s crontab with
crontab -eand add a line using the syntax* * * * * commandor an @directive. - 4. If the task requires environment variables, prepend them in the crontab line or source a wrapper script.
- 5. Redirect output to a file or mail by appending
>> /var/log/cron_task.log 2>&1or| mail -s "Cron output" user@example.com. - 6. Test the new cron entry by running the command manually and checking the log or mail output.
Fonctionnalités clés de cron
- Syntaxe de crontab basée sur le texte
- Prise en charge de la planification par minute, heure, jour, mois et jour de la semaine
- Exécution sous le crontab de n'importe quel utilisateur
- Redirection de la sortie vers des fichiers ou la messagerie
- Gestion des variables d'environnement
- Prise en charge de @reboot, @yearly, @monthly, @weekly, @daily, @hourly
Installer cron sous Linux
sudo apt install cronsudo apt install cronQuestions fréquentes
Can cron run a task only once at a specific time?
Yes, use the at command for one‑off jobs, or schedule a cron job that deletes itself after running.
How do I keep a cron job from running if the machine is off?
Cron only runs when the system is up. To run a job after boot, use the @reboot directive, or rely on systemd timers for more complex conditions.
Can I schedule a cron job to run on a specific user’s login?
No, cron does not trigger on login events. Use pam_motd scripts, ~/.bash_profile, or systemd user timers for login‑based triggers.