Files
org-roam/20230607103155-crontab.org
2025-11-05 09:18:11 +01:00

47 lines
2.0 KiB
Org Mode

:PROPERTIES:
:ID: 94b5e3fb-bbf9-40ec-902f-9e15c74c5f99
:END:
#+title: crontab
#+filetags: :basics:
Crontab is a Unix command that creates a table or list of commands, each of which is to be executed by the [[id:5fada795-19a3-4ba6-97c0-0b70bd728a2f][operating system]]t a specified time and on a regular schedule. Crontab is used to create the crontab file (the list) and later used to change the previously created crontab file.
A crontab is structured as follows: * * * * * command
first *: min (0-59)
second *: hour (0-23)
third *: day (0-31)
fourth *: month (1-12)
fifth *: day of month (0-7) 0&7 are sunday
* crontab-command
** create a crontab
#+begin_src bash
crontab -e
#+end_src
** list crontabs
#+begin_src bash
crontab -l #(as user or [[id:673d1cb1-536b-42f1-a046-40a8937c4283][root]])
crontab -l -u smad user (user=smad)
#+end_src
** before save a crontab a new line is added at the end of the script or the crontab will not be installed
* on this [[id:408e8348-778a-4fbd-a14d-9f3d9c595b4a][cluster]] (all machines as root) crontab is used for doing:
** autoupdate at 0:00 all 15th & 30th in a month with [[id:d88b7b60-742d-4bc0-8b48-3fbcfad2373d][pacman]]
#+begin_src bash
0 0 15,30 * * pacman -Syu --noconfirm
#+end_src
** reboot after autoupdate (1) and that with each machine time-delayed
#+begin_src bash
30 0 15,30 * * /sbin/shutdown -r now
#+end_src
** [[id:daa194c9-63f1-433e-8826-a0b4e9020e16][wireguard]] down & up (one min before reboot) so that a permanent connection of the [[id:70899526-8b7d-4976-94fc-cc07c41e550a][clients]] to the [[id:1af47b07-4205-46ac-837a-ee078067328a][vpn]] [[id:f2b1d5af-1a7d-47a5-95c8-4a85d558419e][server]] is guaranteed
#+begin_src bash
29 0 * * * wg-quick down wg1 && wg-quick up wg1
#+end_src
* on [[id:d54bf885-a702-48bb-b108-e9e982bc5952][W0]] and [[id:80a4104e-af18-4d90-a45e-2c92b51e8c0c][W10]] (user=smad) for doing:
** [[id:56d784ed-a87c-441f-b819-73369760ca32][Backup]]
#+begin_src bash
0 2 * * * /home/smad/backups/backup.sh
#+end_src