Home > Back-end >  Functioning for job crons and Python-crontab
Functioning for job crons and Python-crontab

Time:06-16

guys. I am new on job crons and Python-crontab. Don't understand very well module , I created a simple testcron.py file with

from crontab import CronTab
cron = CronTab(user='root')
job = cron.new(command='echo hello_world')
job.minute.every(1)
cron.write()

I changed permision to 0774, and the execute as python3 testcron.py. Should I see every minute hello_world in my terminal? , because nothing happened. I execute crontab -e and add path/testcron.py, but still i don't see "hello world"

Is missing the os library ?

CodePudding user response:

Should I see every minute hello_world in my terminal?

No.

Is missing the os library ?

No.

Depending on your system configuration, the output may visible in your system logger. See journalctl.

CodePudding user response:

Python-crontab seems to be an interface for the system cron. If it works as advertised, your code should add a new command to the current cron (check with crontab -l). If no commands are added, you may not have sufficient rights (are you running as root?).

Python-crontab does not execute any scheduled tasks itself. I would recommend to get familiar with cron first, before using a programmatic interface.

  • Related