⏳ cron and python

Sat 4 Jun, 2022




jamie@moon:~/Documents/Learning/cron$ vim rand.py

rand.py:

import random
from datetime import datetime

now = datetime.now()
num = random.randint(1 , 100)
with open('/tmp/rand.txt', 'a' ) as f:
        f.write( '{} - with a random number of {}\n'.format(now, num) )

then:

jamie@moon:~/Documents/Learning/cron$ crontab -e

Include:

* * * * * /usr/bin/python3 /home/jamie/Documents/Learning/cron/rand.py

blog.jcaston.uk // 2025