AutomationWritten by GLWS8 min readUbuntu 24.04 LTS / AlmaLinux 9
Commands run on your server unless a section says otherwise. Replace example usernames, addresses and paths with your own values. Keep a working session open when changing remote access.

Use the right account and service

Cron runs commands on a repeating schedule. This example writes a timestamp into a log owned by your normal user; it does not require a root crontab. Use sudo only to install and start the scheduler. Ubuntu 24.04 LTS uses the cron package and service. AlmaLinux 9 uses the cronie package and crond service.

Minimal VPS images may omit the scheduler. Install the appropriate package and verify its service state. Once it is active, return to your normal user for the remaining steps. A user crontab executes with that user's permissions.

Ubuntu 24.04 LTS
sudo apt update
sudo apt install cron
sudo systemctl enable --now cron
systemctl is-active cron
AlmaLinux 9
sudo dnf install cronie
sudo systemctl enable --now crond
systemctl is-active crond

Prepare an explicit log path

Create a private directory in your home directory, then print its absolute path. Replace /home/youruser in the examples below with the path actually printed on your server. If your account has another home-directory location, use that location instead.

Test the same command manually before scheduling it. Cron starts with a smaller environment than your interactive shell, so use full executable paths and full file paths. A job that relies on your current directory or shell aliases can work manually and fail under cron.

Prepare and identify the log directory
mkdir -p "$HOME/cron-logs"
chmod 700 "$HOME/cron-logs"
realpath "$HOME/cron-logs"
Manual test after replacing the path
/usr/bin/date >> /home/youruser/cron-logs/heartbeat.log 2>&1
/usr/bin/tail -n 5 /home/youruser/cron-logs/heartbeat.log

Add a one-minute test

Run crontab -e without sudo. Preserve any existing entries and add the lines shown below. MAILTO with an empty value disables cron's output email; output and errors are instead appended to your local log. End the final line with a newline before saving.

A user crontab entry begins with five fields: minute, hour, day of month, month, and day of week. An asterisk permits every value in that field. Five asterisks therefore schedule this test every minute. User crontabs do not include an extra username field.

Open your user crontab
crontab -e
Add these lines with your actual log path
MAILTO=""
* * * * * /usr/bin/date >> /home/youruser/cron-logs/heartbeat.log 2>&1

Confirm execution

List the saved crontab and allow one or two minute boundaries to pass. Read the log again: new timestamps show that the scheduled command reached its output step. If nothing appears, check the directory path, permissions, and scheduler state.

The service journal can help identify scheduler problems, but a record of a command being launched does not guarantee that the application completed successfully. Keep application output in its own log and use an application-specific success check for important tasks.

Verify the saved entry and output
crontab -l
/usr/bin/tail -n 5 /home/youruser/cron-logs/heartbeat.log
Ubuntu scheduler journal
sudo journalctl -u cron --since '10 minutes ago' --no-pager
AlmaLinux scheduler journal
sudo journalctl -u crond --since '10 minutes ago' --no-pager

Replace the test with a real schedule

Remove just the heartbeat line with crontab -e when finished. For a daily job at 03:15, the schedule begins 15 3 * * *. Confirm the server's timezone with timedatectl; cron schedules normally follow the server's clock. Jobs scheduled while the server is powered off are not generally replayed by ordinary cron. Use a systemd timer when missed-run handling is required.

Check the server's clock and timezone
timedatectl

Official documentation

These upstream references provide more detail on the commands and workflows in this guide.