LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-06-2008, 12:30 AM   #1
niner710
Member
 
Registered: Apr 2008
Posts: 37

Rep: Reputation: 15
Cronjob does not work


Hi, I am trying to setup a cron job in my Fedora distribution but its not working.

These are the steps I took.
1) Setup a perl script in /home/documents/test.pl - Script just gathers the local time.
2) Setup a cron.test file in /etc/cron.d/
3) Executed the perl script and made sure it wrote to cron.test correctly - It works.
4) Create a cron.job file in /etc/cron.d/
5) I changed the permissions of both these files to RWX. Also changed the group from root to my user name.
6) crontab cron.job(load file to system)

This is what my cron.job file looks like.

cron.job
1 * * * * jma perl /home/documents/test.pl

Doesn't seem like the cronjob is working because cron.test never gets written. /etc/log/cron has no entries as well, so it doesn't seem like its entering the function. Can anyone tell me what I'm doing wrong???
 
Old 05-06-2008, 01:31 AM   #2
BugZRevengE
Member
 
Registered: Oct 2005
Location: Australia
Distribution: Slackware & Kubuntu & CentOS
Posts: 106

Rep: Reputation: 17
I know it is weird, but I have had the problem where the files in /etc/cron.daily (or weekly, hourly,etc) have to contain no dot (.).. If they contain a dot (eg backup.sh) they do not work, but without the dot, (backup) it does... I think it is to do with the way run-parts works....

So try renaming cron.job to cron-job and it should work.!
 
Old 05-06-2008, 01:41 AM   #3
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
How do you know it doesn't work? Is it meant to output the time in some way? If so, where to? I take it nothing is emailed to the user?

Itake it jma is a user - have you tried giving a full path to perl (eg /bin/perl)
 
Old 05-06-2008, 01:59 AM   #4
niner710
Member
 
Registered: Apr 2008
Posts: 37

Original Poster
Rep: Reputation: 15
I tried cron-job with no luck.

Yes, I have a perl script that when run, will write to the output file cron.test. I don't see any input in cron.test so I know that the cron job hasn't started correctly. No output is emailed to the user eitehr. I also tried the full path to perl with no luck
 
Old 05-06-2008, 02:34 AM   #5
BugZRevengE
Member
 
Registered: Oct 2005
Location: Australia
Distribution: Slackware & Kubuntu & CentOS
Posts: 106

Rep: Reputation: 17
Sorry - a bit shorter, cause my browser crashed - and i lost the original message I was going to post....

Test the script as the user, so you know that it works...
Make sure you use full paths for the output file... cron does not run from where you think it might, so relative paths are a bit no-no
Check the user has permission for writing to the output file.
as billymayday said, give full path for perl:
1 * * * * jma /usr/bin/perl /home/documents/test.pl
(determine path to perl by running 'which perl')

Hope these help (if not post the contents of the script test.pl here - there might be something... - feel free to replace security info with example data (foo, bar, USERNAME, PASSWORD, SERVER)
 
Old 05-06-2008, 02:34 AM   #6
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Can you post the script?
 
Old 05-06-2008, 11:20 AM   #7
niner710
Member
 
Registered: Apr 2008
Posts: 37

Original Poster
Rep: Reputation: 15
Sure. Here is my test.pl script and my cron-job file that is in my home directory(/home/jma/Documents). I know the script works because when I run it, it writes correctly to "cron.test".

test.pl
#!/usr/bin/perl
open(DATA, ">/home/jma/Documents/cron.test");
@Now = localtime(time);
print DATA "@Now\n";
exit;

cron-job
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
1 * * * * jma /usr/bin/perl /home/jma/Documents/test.pl

I think the permissions are ok because I changed cron.test to "777".

Last edited by niner710; 05-06-2008 at 12:38 PM.
 
Old 05-07-2008, 02:08 AM   #8
niner710
Member
 
Registered: Apr 2008
Posts: 37

Original Poster
Rep: Reputation: 15
I finally got it to work. I think it was this line in my cron-job file.

1 * * * * jma /usr/bin/perl /home/jma/Documents/test.pl

I took out the jma and it worked. Thought I had to include this. Not sure why I don't but I guess it works now.

1 * * * * /usr/bin/perl /home/jma/Documents/test.pl

Thanks for the advice.
 
Old 05-07-2008, 02:13 AM   #9
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE 42.1_64+Tumbleweed-KDE, Mint 17.3
Posts: 3,949

Rep: Reputation: Disabled
Quote:
Originally Posted by niner710 View Post
...
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
1 * * * * jma /usr/bin/perl /home/jma/Documents/test.pl
...
I found no "PATH" statement in the man pages for crontab. Be that as is may, you ask cron to run every minute the job "jma" which seems to be undefined as far as I can see. I don't know whether the "/usr/bin/perl" statement is necessary, so you might try just "/home/jma/Documents/test.pl" in the command field of crontab...

<edit> Ooops, crossposting. Glad you solved it by your own means.

Last edited by JZL240I-U; 05-07-2008 at 02:14 AM. Reason: crossposting
 
Old 05-07-2008, 02:48 AM   #10
BugZRevengE
Member
 
Registered: Oct 2005
Location: Australia
Distribution: Slackware & Kubuntu & CentOS
Posts: 106

Rep: Reputation: 17
I see specifying the user is not supported the way you were(I was not sure about that...)

You would be running the job a root - not always a good idea, unless needed.

If you want to run the job as a user, run "crontab -u jma -e" to edit the crontab for user jma

You should not need to specify /usr/bin/perl if you have the magic shell comment at the top (#!/usr/bin/perl) of your script you are calling.

Hope this bit helps....

PS Good to see you fixed it

Last edited by BugZRevengE; 05-07-2008 at 02:48 AM. Reason: fogot to mention last bit in PS
 
Old 05-07-2008, 04:22 AM   #11
harsshal
Member
 
Registered: Jul 2006
Location: New York, NY
Distribution: redhat,ubuntu,RHEL,fedora,centOS
Posts: 105

Rep: Reputation: 15
These are the fields of an crontab entry(in order)
1.Min 0-59
2.Hrs 0-23
3.Day of month 1-31
4.Month 1-12
5.Week-day 0-6
6.Command sh ./script
 
Old 05-07-2008, 04:45 AM   #12
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Except crontab (as in /etc/crontab) has a user defined, and I think that's what threw people
 
  


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
'lsof' doesn't work in cronjob BlackHatRob Linux - Software 2 03-07-2008 05:03 PM
Cronjob won`t work in /var nodger Linux - Software 3 11-02-2004 07:44 PM
Cronjob engnet Linux - Networking 6 03-03-2004 10:21 AM
Su in a cronjob michedlp Programming 3 11-06-2003 09:30 AM
cronjob FastEddy Linux - General 1 04-12-2003 10:52 PM


All times are GMT -5. The time now is 03:13 AM.

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