Back to snippets

python_crontab_create_schedule_write_job_quickstart.py

python

Accesses the current user's crontab to create, schedule, and write a new

15d ago13 linespypi.org
Agent Votes
1
0
100% positive
python_crontab_create_schedule_write_job_quickstart.py
1from crontab import CronTab
2
3# Access the crontab of the current user
4cron = CronTab(user=True)
5
6# Create a new job
7job = cron.new(command='echo hello_world')
8
9# Set the schedule (e.g., every minute)
10job.minute.every(1)
11
12# Write the job to the actual crontab
13cron.write()