mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-08 21:34:25 +00:00
67 lines
1.3 KiB
Markdown
67 lines
1.3 KiB
Markdown
# Crontab
|
|
|
|
1. [TL;DR](#tldr)
|
|
1. [Further readings](#further-readings)
|
|
1. [Sources](#sources)
|
|
|
|
## TL;DR
|
|
|
|
> [!caution]
|
|
> Escape the `%` character if used in commands (e.g., in `date`'s formatting), even if in quotes.<br/>
|
|
> Cron interprets `%` as a newline. Everything after it is sent to the command's stdin, not as part of the command.
|
|
|
|
```sh
|
|
# List existing jobs.
|
|
crontab -l
|
|
sudo crontab -l -u 'jane'
|
|
|
|
# Edit crontab files.
|
|
crontab -e
|
|
sudo crontab -e -u 'mark'
|
|
|
|
# Replace the current crontab with the contents of a given file.
|
|
crontab 'path/to/file'
|
|
sudo crontab -u 'kelly' 'path/to/file'
|
|
|
|
# Validate crontab files.
|
|
crontab -T '/etc/cron.d/prometheus-backup'
|
|
|
|
# Remove all cron jobs.
|
|
crontab -r
|
|
sudo crontab -r -u 'nana'
|
|
```
|
|
|
|
```txt
|
|
# Run 'pwd' every day at 10PM.
|
|
0 22 * * * pwd
|
|
|
|
# Run 'ls' every 10 minutes.
|
|
*/10 * * * * ls
|
|
|
|
# Run a script at 02:34 every Friday.
|
|
# `%` needs escaping even in quotes
|
|
34 2 * * Fri /absolute/path/to/script.sh
|
|
35 3 * * FRI /absolute/path/to/script.sh > /absolute/path/to/script.$(date '+\%F').log
|
|
```
|
|
|
|
## Further readings
|
|
|
|
- [Cron]
|
|
- [Crontab guru]
|
|
|
|
### Sources
|
|
|
|
- [cheat.sh]
|
|
|
|
<!--
|
|
Reference
|
|
═╬═Time══
|
|
-->
|
|
|
|
<!-- Knowledge base -->
|
|
[cron]: cron.md
|
|
|
|
<!-- Others -->
|
|
[cheat.sh]: https://cheat.sh/crontab
|
|
[crontab guru]: https://crontab.guru/
|