0

I have set up my crontab so it executes my python script every day (for testing purposes I set it to every minute) however the cron tab ignores most of the code

so i tested a bit in order to find where exactly does the script stop:

  • If i put a print statement at the top of the script it will write the output in my logfile - perfect

  • If i put a print statement in line of the script it will also print into the logfile - perfect

however if i have some other code in there it will suddendly stop and do nothing else, for example in this case 0 and 1 gets printed out but 2 does not

print(0)
print(1)

import sys
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import os
import datetime
from bs4 import BeautifulSoup
import re

print(2)

the same problem also occures with other code not just import statements

by the way this is my code in root crontab

 * * * * * /usr/bin/python3 /abc/def/script.py >> /var/log/cron.log
Fabian
  • 9
  • 3
  • You should test your script the way cron runs it, and you'll probably see various error messages: https://stackoverflow.com/q/2135478/476 – deceze Sep 26 '19 at 10:07
  • 1
    You might want to add `2>&1` to the end of your cron command, so that you see the error log there, too – user2390182 Sep 26 '19 at 10:07
  • It sounds like you need to redirect `stderr` (your error output) to the log. Try this: `* * * * * /usr/bin/python3 /abc/def/script.py 2>&1 >> /var/log/cron.log` – S3DEV Sep 26 '19 at 10:08
  • may be Bcoz of you install required packages with other user and running cron using other user. – Shanteshwar Inde Sep 26 '19 at 10:56

0 Answers0