1

I was testing cronjobs for one of my projects. For that I made a simple telegram bot that sends me a message every minute.

The code is the following:

import requests
from datetime import datetime
Token = "Token here"
OWNER_ID = Id here

def send():

send_text="Message sent at : "+str(datetime.now())
telegram_send = f"https://api.telegram.org/bot{Token}/sendmessage?chat_id={OWNER_ID}&text={send_text}"
requests.get(telegram_send)
print("sent at : " , datetime.now())


send()

and my cronjob command was:

* * * * * /usr/bin/python3 /home/anish/cowin/tester.py >> ~/cron.log 2>&1

The bot sent me a message every minute and the log files also recorded it:

sent at :  2021-05-26 14:37:02.681277
sent at :  2021-05-26 14:38:02.444642
sent at :  2021-05-26 14:39:02.189234
sent at :  2021-05-26 14:40:01.932228
sent at :  2021-05-26 14:41:02.695751

And this is what I received in the bot as expected:

bot messages

But when I changed the cronjob command to execute the command between 2pm and 6pm, the program execution stopped.

The new command I entered is:

* 14-18 * * *  /usr/bin/python3 /home/anish/cowin/tester.py >> ~/cron.log 2>&1

Can someone help me out with this problem or point out any error in my code?

Anish
  • 21

1 Answers1

0

I found out that the cron services didn't detected the change in my systems timezone .

I got the issue solved by simply restarting cron services sudo /etc/init.d/cron restart

Anish
  • 21