0

I wrote a python script that checks a website and eventually sends an email. I copied the script to my raspberry and when I execute it via ssh it works fine. But when I let it execute by the crontab it doesn't. In the syslog I can see that the script was executed but I get these errors:

Apr  2 14:25:01 raspberrypi CRON[28850]: (pi) CMD (sudo /usr/bin/python3 /home/pi/Desktop/Script/main.py >> /home/pi/Desktop/Script/log.txt)
Apr  2 14:25:04 raspberrypi sSMTP[28854]: Unable to connect to "smtp.cablelink.at" port 587.
Apr  2 14:25:04 raspberrypi sSMTP[28854]: Cannot open smtp.cablelink.at:587
Apr  2 14:25:04 raspberrypi cron[430]: sendmail: Cannot open smtp.cablelink.at:587
Apr  2 14:25:04 raspberrypi CRON[28849]: (pi) MAIL (mailed 220 bytes of output but got status 0x0001 from MTA#012)

The crontab entry looks like this:

* * * * * /usr/bin/python3 /home/pi/Desktop/Scrabber/main.py >> /home/pi/Desktop/Scrabber/log.txt

I think it's not a problem of permission because for all i can see the crontab is executed as user pi as well as when I use the ssh command.

Thanks in advance.

2
  • I believe this has more to do with your mail setup than with your cron schedule. If you log in via SSH, you say that the mail is sent without issues? Commented Apr 2, 2022 at 12:39
  • Yes when i do it via ssh it works perfect. And also receive the email. Commented Apr 2, 2022 at 12:57

1 Answer 1

1

just found out whats going on. The problem was that in my python script i had a link which was name open('logfile.txt'). When i used the ssh it worked but the cronjob needed the full path like open('home/..../logfile.txt').

Now it works!! YEAH

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.