0

So, I wrote a very small python script that runs a system command whenever it detects a file being over 0 bytes. Tried to schedule a cronjob to run it, but for whatever reason it doesn't work -- what am I doing wrong??

Python script (/usr/local/bin/urlEmail.py):

#!/usr/bin/env python
import os

changes = os.stat("/usr/local/bin/changes.txt")
if changes.st_size > 0:
    os.system('ssmtp email@email.com < changes.txt')

(Right now, changes.txt is static and has some text it in just for my testing)

added to crontable -e on root user:

*/1 * * * * urlEmail.py

And if I look at /var/log/syslog, I see:

Jun 13 07:09:01 Server CRON[20901]: (root) CMD (urlEmail.py)
Jun 13 07:09:02 Server sSMTP[20902]: Sent mail for root@email.com  (221 domain.domain.com closing connection) uid=0 username=root outbytes=577

Also, just running 'urlEmail.py', I get the email I expect, however, the log message is:

Jun 13 07:17:07 Server sSMTP[20952]: Sent mail for root@email.com (221 domain.domain.com closing connection) uid=0 username=root outbytes=352

The only thing that has changed between the two log messages is the fact that in the one where I run 'urlEmail.py' on my own, outbytes value is different.

When the cron runs (once a minute) I'm not getting any emails at all.

Ben
  • 157
  • 1
  • 1
  • 13

0 Answers0