Skip to content

Q&A · Answered

How to schedule tasks with cron on Linux

asked 9 months, 1 week ago 2158 views 1 answer
1

I need to run a backup script every night at 2 AM. How do I set up a cron job?

1 Answer

One accepted
23

Accepted answer

Not confirmed since it was written, 9 months, 1 week ago

Edit crontab

# Edit user crontab
crontab -e

# Cron format: minute hour day month weekday command
# Run at 2:00 AM every day
0 2 * * * /path/to/backup.sh

# Run every 5 minutes
*/5 * * * * /path/to/script.sh

# Run on Sundays at midnight
0 0 * * 0 /path/to/weekly.sh

Useful cron examples

# View current crontab
crontab -l

# Run command with full paths
0 2 * * * /usr/bin/python3 /home/user/backup.py >> /var/log/backup.log 2>&1

Your answer

Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.

Shown beside your answer and never checked, so it cannot be a name someone already has here.

No account needed to answer. Sign in instead and it carries your name and earns reputation.