Find the answer to your Linux question:
Results 1 to 4 of 4
I have two different versions of Scientific Linux(6.3 and 4.6) running on two different computers. The user is mcqa on both systems I'm playing about a bit with crontab and ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2013
    Posts
    3

    Crontab python not outputting to file


    I have two different versions of Scientific Linux(6.3 and 4.6) running on two different computers. The user is mcqa on both systems

    I'm playing about a bit with crontab and python and decided to make a simple test. This is my python script:

    Code:
        #!/usr/bin/python
        newTime = '123'
        myFile = '/home/mcqa/MCQA/hello.list'
        f = open(myFile, 'w')
        f.write('Hello at {0}\n'.format(newTime))
        f.close()
    Runnig it from the prompt is fine on either system and it produces the expected output. Next I added the following line to crontab

    Code:
        * * * * * python /home/mcqa/MCQA/helloTime.py
    Now, on the 6.3 setup it still works as expected and the file gets updated every minute. On the 4.6 system however, an empty-file is created every minute. Why do they behave differently?

    If I instead use a similair shell script instead of the helloTime.py everything is OK on both systems.

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    hello and welcome!

    in order to try and catch any errors, try adding a bit of logging to your cron job:

    Code:
    * * * * * python /home/mcqa/MCQA/helloTime.py > /tmp/cronjob.log 2>&1
    hopefully, the log file created will have some output in it that will help.

  3. #3
    Just Joined!
    Join Date
    Mar 2013
    Posts
    3
    Quote Originally Posted by atreyu View Post
    hello and welcome!

    in order to try and catch any errors, try adding a bit of logging to your cron job:

    Code:
    * * * * * python /home/mcqa/MCQA/helloTime.py > /tmp/cronjob.log 2>&1
    hopefully, the log file created will have some output in it that will help.
    Cron ran a older version of python which did not support the format attribute of str, so specifying /usr/local/bin/python solved the issue. Thanks

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by MarchColorDrink View Post
    Cron ran a older version of python which did not support the format attribute of str, so specifying /usr/local/bin/python solved the issue.
    ah, there's the rub. path.

    i'll go ahead and mark this Solved for you. FYI, you can do this as well, using the Thread Tools link at the top of the page.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •