0

I have a python script I want to fire off every night at midnight. I'm using cron scheduler right now to do so, however, I can't figure out why it's not working. For now, I've been using close times (within the next minute or so) to test the cronjob, but I will ultimately want it to work for midnight.

Here is what I put in my crontab file (to run for 2:43pm), hosted on my ubuntu machine:

43 14 * * * root /home/grantmcgovern/Developer/Projects/StudyBug/Main.py

I even put the:

#!user/bin/python 

on top of all the .py files.

I also did:

chmod +x "scriptname".py

For each of the .py files and still no luck. Am I missing something blatantly obvious? I should note, this is my first time playing with cron tasks.

15
  • 2
    The shebang line (the first line in the Python scripts) should look like #!/usr/bin/python, not #!user/bin/python. Commented Apr 18, 2014 at 18:51
  • @bdesham Thanks for that catch, still no luck though. Commented Apr 18, 2014 at 18:54
  • As an alternative to #!/usr/bin/python ... #!/usr/bin/env python Commented Apr 18, 2014 at 18:55
  • 1
    you can log the execution by adding > /tmp/mycronlog.log at the end making it 43 14 * * * root /home/grantmcgovern/Developer/Projects/StudyBug/Main.py > /tmp/mycronlog.log. What does the log say? Commented Apr 18, 2014 at 19:02
  • 1
    That is telling you that you are trying to run a program named root. Commented Apr 18, 2014 at 19:17

2 Answers 2

2

From your current crontab file, you're basically running root /home/grantmcgovern/Developer/Projects/StudyBug/Main.py every time.

If you want to run it as root, use sudo crontab -e and put 43 14 * * * /usr/bin/python /home/grantmcgovern/Developer/Projects/StudyBug/Main.py instead.

Sign up to request clarification or add additional context in comments.

Comments

1

I think it is looking for the command "root" so the syntax is wrong, so it should be this...

43 14 * * * /home/grantmcgovern/Developer/Projects/StudyBug/Main.py

If you need it to run as root then I think you can use su like this:

43 14 * * * su root -c "/home/grantmcgovern/Developer/Projects/StudyBug/Main.py"

If you add it to the system crontab then I think it will anyway.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.