LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Basic Cron Job Help! (https://www.linuxquestions.org/questions/linux-newbie-8/basic-cron-job-help-635496/)

sbabcock23 04-15-2008 09:57 AM

Basic Cron Job Help!
 
Hi Everyone,
I am trying to create a cron job that runs every 4 hours. This is what I put in my crontab file:
01 */4 * * * tester/home/tester/ff/python ff.py

I get this error however
/bin/sh: /home/tester/ff/python: No such file or directory

All I'm trying to do is create a cron job that runs the command "python ff.py" every 4 hours. Can anyone help me here?

Thanks
I'm using Fedora btw.

lord-fu 04-15-2008 10:10 AM

It wont work like that. Create a script under the home directory and make it executable, in that script call the python interpreter and script.
Code:

01 */4 * * * tester /home/tester/ff/myscript
In myscript

python ff.py

Something like that.

hth

forrestt 04-15-2008 10:41 AM

That won't work either as the file "tester" probably doesn't exist either. And, if /home/tester/ff/python is the path to the python interpreter, then it should work fine the way you are trying to do it. However, you have a path of "tester/home/tester/ff/python". Are you sure your error message isn't:

Code:

/bin/sh: tester/home/tester/ff/python: No such file or directory
You don't specify a user in a crontab entry. The cron job will be run by the owner of that particular crontab. If you need to run a cron job as a particular user, create a different crontab file for that user (crontab -e username).

Try this instead:
Code:

01 */4 * * * /home/tester/ff/python ff.py
HTH

Forrest

sbabcock23 04-15-2008 10:58 AM

sorry, my mistake there should be a space in there i just copied it down wrong when posting this
it actually appears like this:
/bin/sh: tester /home/tester/ff/python: No such file or directory

I'll try lord-fu suggestion

Thanks

lord-fu 04-15-2008 11:16 AM

In my example tester is the "who" not a path.


Edit: forrest is correct though a user should have their own crontab if you are wanting to run jobs as that user.
And on that note I have 666 posts, there goes my day :[

forrestt 04-15-2008 11:38 AM

lord-fu & sbabcock23, I think the problem may be that you are trying to edit a non-system crontab entry with a system crontab entry format. Only the system crontab (/etc/crontab) uses the user field. The root crontab doesn't, and neither do any for normal users.

sbabcock23, If you are running "crontab -e" as root to edit the crontab, then there isn't a user field as this is the root user's crontab, not the system crontab. The entire line after the time specifications is treated as the command/options. If you are editing /etc/crontab directly, then you would use a user field. I typically leave this file alone and create per user crontab entris as it makes copying crontab entries from Linux to Solaris and back compatible. If you are running "crontab -e" as the tester user (what I suggest) then you will also not have a user field in the crontab entry.

HTH

Forrest

lord-fu 04-15-2008 12:19 PM

That is correct forrest I was under the impression in the op example that this was the system crontab, therfore I left the user entry in my example. Sorry for any confusions.

And on that note I am above 666 posts, whew.

forrestt 04-15-2008 12:20 PM

Yeah, your post count was getting me a little worried.

:)

sbabcock23 04-15-2008 07:25 PM

hey, I got the cron to work except, in my python code I have file = open(filename, 'a') and python is throwing an error:
sys.stdout = open(logfile, 'a')
IOError: [Errno 13] Permission denied: 'log.txt'

but this works if I run it manually but not from the cron job. I added the cron job by using the command crontab -e.

Any suggestions?

Thanks

forrestt 04-16-2008 11:31 AM

Try using the full path to log.txt.

HTH

Forrest

sbabcock23 04-16-2008 02:47 PM

yup that worked thanks!


All times are GMT -5. The time now is 03:56 PM.