From 38bcdd15cc1038f6da02a2f2129b5a01af7d7358 Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Fri, 22 Mar 2024 18:58:20 +0100 Subject: [PATCH] embiggen cron --- basics/cron.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/basics/cron.md b/basics/cron.md index 2983cab..8c66feb 100644 --- a/basics/cron.md +++ b/basics/cron.md @@ -14,20 +14,31 @@ Once installed, search for the service name, and start it. ```bash sudo systemctl list-unit-files | grep cron +sudo systemctl enable --now $NAME ``` +Make a file for your crontab, like this: + ```bash -sudo systemctl enable --now cron +echo '39 */3 * * * /usr/bin/updatedb' > "$USER".cron ``` -You can *e*dit your crontab with: +Then apply that crontab: ```bash -crontab -e +crontab "$USER".cron +rm "$USER".cron ``` +The `cron` program will check your syntax before adding the tab. +Your crontab file sits somewhere in `/var/spool/`. +Probably in `/var/spool/cron`. -> 39 */3 * * * /usr/bin/updatedb +Check how your tab currently looks: + +```bash +crontab -l +``` ## Syntax @@ -91,7 +102,7 @@ run-parts /etc/cron.hourly ### Variables Add your `$HOME` to crontab to use scripts. -First add `HOME=/home/user`, then you can use syntax like this: +First add `HOME=/home/$USER`, then you can use syntax like this: 0 * * * * $HOME/.scripts/myScript.sh @@ -100,7 +111,6 @@ First add `HOME=/home/user`, then you can use syntax like this: ```bash $HOME/.scripts/myScript.sh ``` - You can also add your regular path to your crontab as a variable (see example below). If you're using vim as the editor, just run this at the top of your crontab: @@ -131,5 +141,3 @@ PATH=/usr/condabin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/u 50 18 * * * /usr/bin/timeout 30m /usr/bin/syncthing ``` - -