Search code examples
pythonunixcronsyslog

cron python script logging messages syslog


I use cron to control a python script

*/10 * * * * /usr/bin/python3 /home/user/FillDatabase.py

and its works well so fare. The python script itself produce logging in case of error.

import logging
...
logging.basicConfig(level=logging.INFO, format="[%(module)s] %(message)s")
...
try:
    ...

except Exception as e:
    logging.info('error while writing: {0} \n'.format(e))

I want so see these python logging messages in the syslog.

i tried

*/10 * * * * /usr/bin/python3 /home/user/FillDatabase.py 2>&1

Solution

  • found:

    Wirte to cron with

    sudo crontab -u root -e
    

    give cron the permission to write into syslog

    */10 * * * * /usr/bin/python3 /home/user/FillDatabase.py >> /var/log/syslog 2>&1