cronjobs

Installation

Artix Linux

sudo pacman -S cronie cronie-openrc
sudo rc-service cronie start
rc-update add cronie default 

Usage

Command: crontab [options] Edit crontab: crontab -e

Inside the crontab:

Each line of the file represents a different cronjob, one line should be structured as such:

* * * * *  <command or path to script>

By using the stars, or substituting them with values, you can set the times at which you wish a certain command to be executed. This is useful for automating boring jobs if you know when and/or how often you would need to do them. You may want to run some command for example every minute, or every other hour, or every working day at 6pm and 6am, every new years eve, or every 7th minute from 3pm-9pm, if it’s february the 29th and also a sunday or a tuesday. You can do almost anything really.

Stars represent:

  1. Minute
  2. Hour
  3. Date
  4. Month
  5. Day of week Respectively.
1. 2. 3. 4. 5.
* * * * *
ID: Minute Hour Date Month Day of week
Value: 0 - 59 0 - 23 1 - 31 1 - 12 0 - 6

0th day of the week is Sunday, 6th is Saturday

If there is a star instead of a value it simply means every [ID] corresponding to that stars position. A * at the 1st position would mean every minute, a * at the 2nd position would mean every hour, and so on…

Example:

0 0 * * 0 shutdown

Means run the command ‘shutdown’

  1. On the 0th Minute
  2. On the 0th Hour
  3. Every date of the month
  4. Every month of the year
  5. On Sunday

In short, run shutdown, every Sunday at 00:00.

Another example

* * * * * echo "A minute has passed" > ~/time

Runs the command echo "A minute has passed" > ~/time every single minute.

And another one

*/10 * * * * dunstify Remember to blink.

Reminds me to blink every 10 minutes.

Doing Graphical Stuff

For doing graphical stuff like spawning a window, a notification, setting a wallpaper, or anything else of that nature, just prepend the display number to the beginning of the crontab as such:

DISPLAY=:0
* * * * * dosomething.sh

If you’d like to use different screens, or only want this for certain cronjobs, you can add it right before the script as such:

* * * * * DISPLAY=:0 dosomething.sh
* * * * * DISPLAY=:1 dosomethingelse.sh
* * * * * dosomethingelseelse.sh
 

melans cave

computers and transistors and whatnot


2025-02-02