LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 07-29-2005, 12:22 PM   #1
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Rep: Reputation: 15
cron issue


Hi all,

I am new in linux and i was trying to excute one perl file using cron. but it is not going to excute after 1 minute.

I created two files

1-
==============test.cron===============
0,1,30,45 * * * * /usr/local/cron/test.pl
==============End test.cron file=========

2-
===============test.pl================
#!/usr/bin/perl

use DBI;

my $db_host = '10.0.0.20';
my $db_user = 'linux';
my $db_pass = '123456';
my $db_name = 'auto';

my $db = "dbi:mysql:dbname=${db_name};host=${db_host}";

$dbh = DBI->connect($db, $db_user, $db_pass,
{ RaiseError => 1, AutoCommit => 0 }
) || die "Error connecting to the database";

$dbh->do("INSERT INTO test(name)
VALUES(?)", undef,"Thanx for insert");

=================== End of test.pl file =======

When i start the crontab it is started successfully from the following commond

[root@localhost cron]# crontab test.cron

[root@localhost cron]# crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (test.cron installed on Fri Jul 29 20:07:46 2005)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
0,1,30,45 * * * * /usr/local/cron/test.pl[root@localhost cron]#


And the perl file is ok if i am using perl test.pl the all scripts of perl is working fine.

Can anyone tell me where i am doing the wrong.

Thank You
 
Old 07-29-2005, 01:53 PM   #2
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
I don't understand exactly what the problem is. You say it's executing correctly with 'crontab.test' ?

If you use 'crontab -e' you can edit your crontab and make it a permanent cron job under whatever user you might be logged in as.

I'm not sure what the problem is that you are trying to state.
 
Old 07-29-2005, 01:56 PM   #3
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Original Poster
Rep: Reputation: 15
It is not excuting with crontab.test but the same perl file can be excuted successfully with perl commond on console.
 
Old 07-29-2005, 02:19 PM   #4
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
Okay, I understand now, thank you.

I just referred to the man page for crontab. If I read it correctly, 0,1,30,45.... will cause it to execute at the top of the hour, 1 minute past the hour, 30 minutes past the hour, and 45 minutes past the hour.

And it sounded like you wanted it to run 1 minute after running 'crontab crontab.test'. See the difference?

I'm not sure how to get cron to do that actually. You can set it to run every minute for the test:
*/1 * * * *
 
Old 07-29-2005, 11:22 PM   #5
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Original Poster
Rep: Reputation: 15
Thanx andey,

But i am really sorry to say that i tested with the your given time interval format. But no more luck.

i tested with also like :

*/1 * * * * perl /usr/local/cron/test.pl

and
*/1 * * * * /usr/local/cron/test.pl

But no luck.
 
Old 07-30-2005, 09:50 AM   #6
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
Okay.. perhaps you could try this for troubleshooting:

*/1 * * * * /usr/local/cron/test.pl_>>$HOME/crontest.log_2>&1

and then keep an eye on that log real-time with:
tail -f $HOME/crontest.log

I would like to think that you'd at least get some kind of error message every minute using that crontab. I used underscores there to indicate spaces. Make sure you don't use the underscores.
 
Old 07-30-2005, 11:31 PM   #7
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Original Poster
Rep: Reputation: 15
Hello Andy,

I did the following modification in my test.cron file.

*/1 * * * * /usr/local/cron/test.pl >/tmp/perll.log 2>&1

And i restart the machine, after that it start to work. but when i am trying crontab -l i found that it is using KCron. I cannot see any log in perll.log file.


How i can make the format to execute test.pl file every seconds?
 
Old 07-31-2005, 11:31 AM   #8
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
Quote:
Originally posted by abdul_zu
Hello Andy,

I did the following modification in my test.cron file.

*/1 * * * * /usr/local/cron/test.pl >/tmp/perll.log 2>&1
You have to use _two_ angle brackets (before the '/tmp/perll.log'), so your log will be appended. With only one, the log file will be recreated each time it is written to.


Quote:
And i restart the machine, after that it start to work. but when i am trying crontab -l i found that it is using KCron. I cannot see any log in perll.log file.
It's working now? But no logging? I use Dillon's cron. I don't know anything Kcron. You should be able to see whatever crontab is currently being used by 'crontab -l' and also, on my system anyway, all the crontabs are stored in /var/spool/cron

Quote:
How i can make the format to execute test.pl file every seconds?
Read thru the man page for crontab, or search Google. I don't know if it's possible; I don't recall seeing any options for seconds. I don't have any more information for you, but I wish you luck finding the solution.

Last edited by Andy Alt; 07-31-2005 at 11:33 AM.
 
Old 07-31-2005, 11:39 PM   #9
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Original Poster
Rep: Reputation: 15
Hi Andy,

Thank you very much for your kind of help and company. really i a approciate it.

I am going to search about the seconds. if i will find anything let you know.

Thank You
 
  


Reply



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
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
cron issue, php script runs fine in browser and cli dtra Linux - Software 1 07-15-2005 05:45 AM
rmmod and cron issue? Manuel-H Linux - Software 1 10-23-2004 07:05 AM
[cron][mdk9.1]cron deamon seems to ignore some task... yannrichet Linux - Newbie 5 06-26-2003 09:57 AM
dual entries in cron log for cron.daily cpharvey Linux - General 3 02-27-2003 02:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:33 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
Open Source Consulting | Domain Registration