Running cron jobs
Cron jobs are a type of service that runs on a schedule. We can run a cron job with yeet
like this:
yeet cron <service> <file> <cron_expression>
To set up a cron job, you need to specify the binary or shell script you want to run, along with the schedule. The schedule is defined using a cron expression, which consists of five fields representing the minute, hour, day of the month, month, and day of the week.
For example, to run a script every day at midnight, you would use the following cron expression:
yeet cron my_service script.sh "0 0 * * *"
This command creates a service called my_service
and sets up a Systemd timer unit to run according to the specified cron expression.
Examples
Deploying a backup script
In this example, we'll deploy a fictional backup script. Our script will call tar
to create a backup of a directory, and then upload the resulting file to S3.
#! /bin/bash
tar -czvf /home/user/backups/backup.tar.gz /home/user/important_data
aws s3 cp /home/user/backups/backup.tar.gz s3://my-backup-bucket/
With our shell script written, let's deploy this script as a cron job that runs every day at midnight.
yeet cron s3-backup script.sh "0 0 * * *"
This command creates a service called s3-backup
and sets up a Systemd timer unit to run according to the specified
cron expression.