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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-29-2005, 12:22 PM
|
#1
|
Member
Registered: Feb 2005
Posts: 71
Rep:
|
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
|
|
|
07-29-2005, 01:53 PM
|
#2
|
Member
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 531
Rep: 
|
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.
|
|
|
07-29-2005, 01:56 PM
|
#3
|
Member
Registered: Feb 2005
Posts: 71
Original Poster
Rep:
|
It is not excuting with crontab.test but the same perl file can be excuted successfully with perl commond on console.
|
|
|
07-29-2005, 02:19 PM
|
#4
|
Member
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 531
Rep: 
|
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 * * * *
|
|
|
07-29-2005, 11:22 PM
|
#5
|
Member
Registered: Feb 2005
Posts: 71
Original Poster
Rep:
|
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.
|
|
|
07-30-2005, 09:50 AM
|
#6
|
Member
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 531
Rep: 
|
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. 
|
|
|
07-30-2005, 11:31 PM
|
#7
|
Member
Registered: Feb 2005
Posts: 71
Original Poster
Rep:
|
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?
|
|
|
07-31-2005, 11:31 AM
|
#8
|
Member
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 531
Rep: 
|
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.
|
|
|
07-31-2005, 11:39 PM
|
#9
|
Member
Registered: Feb 2005
Posts: 71
Original Poster
Rep:
|
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
|
|
|
All times are GMT -5. The time now is 04:26 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|