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.
sudo apt update
sudo apt install cron
sudo systemctl enable --now cron
systemctl is-active cronsudo dnf install cronie
sudo systemctl enable --now crond
systemctl is-active crondPrepare 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.
mkdir -p "$HOME/cron-logs"
chmod 700 "$HOME/cron-logs"
realpath "$HOME/cron-logs"/usr/bin/date >> /home/youruser/cron-logs/heartbeat.log 2>&1
/usr/bin/tail -n 5 /home/youruser/cron-logs/heartbeat.logAdd 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.
crontab -eMAILTO=""
* * * * * /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.
crontab -l
/usr/bin/tail -n 5 /home/youruser/cron-logs/heartbeat.logsudo journalctl -u cron --since '10 minutes ago' --no-pagersudo journalctl -u crond --since '10 minutes ago' --no-pagerReplace 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.
timedatectlOfficial documentation
These upstream references provide more detail on the commands and workflows in this guide.