LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-15-2008, 10:57 AM   #1
sbabcock23
Member
 
Registered: Aug 2006
Location: Mississauga, Ontario, Canada
Distribution: RHEL 5, CentOS 5
Posts: 64

Rep: Reputation: 15
Exclamation 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.
 
Old 04-15-2008, 11:10 AM   #2
lord-fu
Member
 
Registered: Apr 2005
Location: Ohio
Distribution: Slackware && freeBSD
Posts: 676

Rep: Reputation: 30
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

Last edited by lord-fu; 04-15-2008 at 12:33 PM.
 
Old 04-15-2008, 11:41 AM   #3
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
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

Last edited by forrestt; 04-15-2008 at 11:42 AM.
 
Old 04-15-2008, 11:58 AM   #4
sbabcock23
Member
 
Registered: Aug 2006
Location: Mississauga, Ontario, Canada
Distribution: RHEL 5, CentOS 5
Posts: 64

Original Poster
Rep: Reputation: 15
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
 
Old 04-15-2008, 12:16 PM   #5
lord-fu
Member
 
Registered: Apr 2005
Location: Ohio
Distribution: Slackware && freeBSD
Posts: 676

Rep: Reputation: 30
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 :[

Last edited by lord-fu; 04-15-2008 at 12:32 PM.
 
Old 04-15-2008, 12:38 PM   #6
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
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
 
Old 04-15-2008, 01:19 PM   #7
lord-fu
Member
 
Registered: Apr 2005
Location: Ohio
Distribution: Slackware && freeBSD
Posts: 676

Rep: Reputation: 30
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.
 
Old 04-15-2008, 01:20 PM   #8
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
Yeah, your post count was getting me a little worried.

 
Old 04-15-2008, 08:25 PM   #9
sbabcock23
Member
 
Registered: Aug 2006
Location: Mississauga, Ontario, Canada
Distribution: RHEL 5, CentOS 5
Posts: 64

Original Poster
Rep: Reputation: 15
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
 
Old 04-16-2008, 12:31 PM   #10
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
Try using the full path to log.txt.

HTH

Forrest
 
Old 04-16-2008, 03:47 PM   #11
sbabcock23
Member
 
Registered: Aug 2006
Location: Mississauga, Ontario, Canada
Distribution: RHEL 5, CentOS 5
Posts: 64

Original Poster
Rep: Reputation: 15
yup that worked thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
cron job somsahi Linux - Software 2 10-24-2006 06:40 AM
cron job somsahi Linux - Software 9 10-05-2006 03:19 PM
cron job? dr_zayus69 Linux - Newbie 14 12-01-2004 07:16 PM
Cron Job imanahmadi Linux - Newbie 1 07-04-2003 12:39 AM


All times are GMT -5. The time now is 07:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration