2

So I'm trying to have my server execute a Python script every hour.

When I go into the directory and run it with python twitter.py, it works fine.

However, I have this entry in crontab and it doesn't work:

0 * * * * /run/twitterparse/twitter.py > /run/twitterparse

I am trying to have it execute every hour, on the hour.

Here's the output to the syslog:

Aug 5  13:00:01 localhost CRON[11474]: (root) CMD (/run/twitterparse/twitter.py >/run/twitterparse/)

Aug 5  13:00:01 localhost CRON[11473]: (CRON) info (No MTA installed, discarding output)

Now what it should be doing is accessing a database and saving information from the web to that database. The script does that fine when run manually, but not automatically.

Steven Matthews
  • 9,705
  • 45
  • 126
  • 232

3 Answers3

2

I fixed my problem by doing this

0 * * * * python /run/twitterparse/twitter.py > /run/twitterparse

and the py file should be executable

chmod +x twitter.py
Rakesh
  • 81,458
  • 17
  • 76
  • 113
1

You probably need to add

#!/usr/bin/python

to the beginning of the main script, with the location of YOUR python interpreter.

and change the permissions of the script to executable

chmod +x <main script name .py>

Hope this helps

j0N45
  • 334
  • 1
  • 12
0

Any output of a cron script that goes to the terminal (i.e. stdio or stderr) is sent to the person who's account the script is registered under.

You can see from the error message that it is trying to send this mail but "No MTA is installed" so it is discarding all the diagnostic messages.

Your first step would be to either fix the problem with the MTA so you can receive the mail or to make sure that stdio and stderr are written to a log file.

The obvious problem that I can see is that the output is being directed to a non-file.

/run/twitterparse/twitter.py > /run/twitterparse

Isn't /run/twitterparse a folder? I guess:

/run/twitterparse/twitter.py > /run/twitterparse/ouput.txt

would solve half the issues..

Stuart Woodward
  • 2,138
  • 4
  • 21
  • 31