|
Home > Archive > Unix administration > August 2005 > Cron task
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| Hi :
I am new of linux. Try to use crontab -e schedule my PERL task.
The situation is :
1> use root to crontab -e;
2> the PERL use the relative directory to access the directory and
file;
I try to check the /var/cron . find the crontab works , however , I
canot find the data file created.
My question is :
Do I must use the aribitrary directory in the PERL program?
Is anything else to effect the cron execu?
Thanks for any help.
yezi
| |
| Bill Marcum 2005-08-08, 5:54 pm |
| On 8 Aug 2005 10:42:23 -0700, yezi
<ye_line@hotmail.com> wrote:
> Hi :
>
> I am new of linux. Try to use crontab -e schedule my PERL task.
>
> The situation is :
> 1> use root to crontab -e;
> 2> the PERL use the relative directory to access the directory and
> file;
>
> I try to check the /var/cron . find the crontab works , however , I
> canot find the data file created.
>
> My question is :
>
> Do I must use the aribitrary directory in the PERL program?
> Is anything else to effect the cron execu?
>
> Thanks for any help.
>
Can you post your PERL script and the "crontab -l"?
--
Tonight you will pay the wages of sin; Don't forget to leave a tip.
| |
|
| Sure.
The PERL is following:
#!/usr/bin/perl -w
use strict;
my $filename;
my $cmdline;
my @newname;
my @newname1;
my $filename1;
my @rmfile;
my ($hour,$day) = (localtime)[2,3];
$filename="/home/binye/data/test_perl/testdownload.txt";
open( FILE, "< $filename" ) or die "Can't open $filename : $!";
while( <FILE> ) {
chomp($_);
@newname=split(/\//,$_);
@newname1=split(/\./,$newname[2]);
push(@rmfile,pop(@newname));
print "Processing wget.\n";
system("wget -w 50 -q $_ &"); #####???????????????????????
print" processing tcpdump $_... \n";
system("tcpdump -c 1000 -i eth0 src host $newname[2] -w
/home/binye/data/test_perl/$newname1[2].$hour.$day.dmp");
print "done ...w $_..\n";
}
foreach $filename1 (@rmfile)
{
system("rm -f /root/$filename1");
print" remove the $filename1 in the root for crontab ... \n";
}
close FILE;
~
~
The crontab is
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.31608 installed on Mon Aug 8 11:25:40 2005)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp
$)
# Collect the data every hour every day from 5 sites to the current
dirctory
30 0-23 * * * PERL /home/binye/data/test_perl/trial1.pl
The object of task is collece the data each hour in one day. and get
all the dmp files and remove whatever downloaded file . Thanks for any
suggestion
| |
| Robert Melson 2005-08-08, 5:54 pm |
| In article <1123534221.950972.202210@g47g2000cwa.googlegroups.com>,
"yezi" <ye_line@hotmail.com> writes:
> Sure.
> The PERL is following:
> #!/usr/bin/perl -w
> use strict;
>
>
> my $filename;
> my $cmdline;
> my @newname;
> my @newname1;
> my $filename1;
> my @rmfile;
> my ($hour,$day) = (localtime)[2,3];
>
>
> $filename="/home/binye/data/test_perl/testdownload.txt";
> open( FILE, "< $filename" ) or die "Can't open $filename : $!";
> while( <FILE> ) {
>
>
> chomp($_);
> @newname=split(/\//,$_);
> @newname1=split(/\./,$newname[2]);
> push(@rmfile,pop(@newname));
>
>
> print "Processing wget.\n";
> system("wget -w 50 -q $_ &"); #####???????????????????????
> print" processing tcpdump $_... \n";
> system("tcpdump -c 1000 -i eth0 src host $newname[2] -w
> /home/binye/data/test_perl/$newname1[2].$hour.$day.dmp");
> print "done ...w $_..\n";
> }
>
>
> foreach $filename1 (@rmfile)
> {
> system("rm -f /root/$filename1");
> print" remove the $filename1 in the root for crontab ... \n";
> }
> close FILE;
> ~
> ~
> The crontab is
>
> # DO NOT EDIT THIS FILE - edit the master and reinstall.
> # (/tmp/crontab.31608 installed on Mon Aug 8 11:25:40 2005)
> # (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp
> $)
> # Collect the data every hour every day from 5 sites to the current
> dirctory
> 30 0-23 * * * PERL /home/binye/data/test_perl/trial1.pl
>
>
> The object of task is collece the data each hour in one day. and get
> all the dmp files and remove whatever downloaded file . Thanks for any
> suggestion
>
I could be way off, but you seem to be using the "shebang" line in your perl
script, which means you don't need to invoke PERL in your crontab, assuming
the script has execute permissions set. If the script runs satisfactorily
from the command line, then the call to "perl <script_name>" could be
rewritten as "<script_name>". Otherwise, unless PERL is in the default path
for root/cron, you should specify the full path to PERL in the crontab.
HTH,
Bob Melson
--
Robert G. Melson | Rio Grande MicroSolutions | El Paso, Texas
-----
"One of the greatest delusions in the world is the hope that the evils in this world are to be cured by legislation." Thomas Reed
-----
| |
|
| Hi:
I try to clear the path problem, now through the ps, I can find the
wget is already run by crontab however the tcpdump can not work
through. By check the path defination , tcpdump can rum manually
without any problem. SO My question is crontab accept like 2 system
call in one PERL program?
Thanks for any comment.
| |
| Bit Twister 2005-08-08, 5:54 pm |
| On 8 Aug 2005 15:10:42 -0700, yezi wrote:
> Hi:
>
> SO My question is crontab accept like 2 system
> call in one PERL program?
Yes. Go back and fully qualify each system call app, examples:
/usr/sbin/tcpdump
/bin/rm
| |
|
| Hi : after check all the path in the PERL , the original code change to
the following:more trial1.pl
#!/usr/bin/perl -w
use strict;
my $filename;
my $cmdline;
my @newname;
my @newname1;
my $filename1;
my ($hour,$day) = (localtime)[2,3];
$filename="/home/binye/data/test_perl/testdownload.txt";
open( FILE, "< $filename" ) or die "Can't open $filename : $!";
while( <FILE> ) {
chomp($_);
@newname=split(/\//,$_);
@newname1=split(/\./,$newname[2]);
print "Processing wget.\n";
system("wget -w 50 -o log --delete-after $_ &
/usr/sbin/tcpdump/tcpdump -c 1000 -i eth0 src host $newname[2] -w
/home/binye/data/test_perl/$newname1[2].$hour.$day.dmp ");
#####???????????????????????
}
close FILE;
Curious of the system call (command 1 & command2 ) is suitable for
cront?
thanks
| |
| Bit Twister 2005-08-08, 8:48 pm |
| On 8 Aug 2005 15:55:43 -0700, yezi wrote:
>
> Curious of the system call (command 1 & command2 ) is suitable for
> cront?
Depends.
What you can run into is $PATH not set correctly for whatever
external applications you call.
To find out, place an
system("/bin/echo $PATH > /tmp/path.txt ");
at the start of your PERL script.
run it though cron and cat /tmp/path.txt
then run it interactive and cat /tmp/path.txt
If you do not want to qualify application paths, then create a
ksh/bash/sh script export the PATH with what you want/need then call
your PERL script. Example follows:
#!/bin/sh
PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/games:\
/sbin:/usr/sbin:/site/bin:/home/bittwister/bin:/opt/jdk1.5.0_02/bin
export PATH
/wherever/perl_script_name.here
#*********** end sh script *****************************
| |
| Liam Cunningham 2005-08-09, 5:56 pm |
| On Mon, 08 Aug 2005 15:55:43 -0700, yezi wrote:
> Hi : after check all the path in the PERL , the original code change to
> the following:more trial1.pl
> #!/usr/bin/perl -w
> use strict;
>
>
> my $filename;
> my $cmdline;
> my @newname;
> my @newname1;
> my $filename1;
> my ($hour,$day) = (localtime)[2,3];
>
>
> $filename="/home/binye/data/test_perl/testdownload.txt";
> open( FILE, "< $filename" ) or die "Can't open $filename : $!";
> while( <FILE> ) {
>
>
> chomp($_);
> @newname=split(/\//,$_);
> @newname1=split(/\./,$newname[2]);
>
>
> print "Processing wget.\n";
> system("wget -w 50 -o log --delete-after $_ &
> /usr/sbin/tcpdump/tcpdump -c 1000 -i eth0 src host $newname[2] -w
> /home/binye/data/test_perl/$newname1[2].$hour.$day.dmp ");
> #####???????????????????????
> }
>
>
> close FILE;
>
> Curious of the system call (command 1 & command2 ) is suitable for
> cront?
>
> thanks
Check the path name for tcpdump. You have '/usr/sbin/tcpdump/tcpdump'. I
suspect it should simply be '/usr/sbin/tcpdump'
--
If at first you don't succeed,
read the manual......
| |
|
|
|
|
|