Cron task - Unix

This is a discussion on Cron task - Unix ; 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 ...

+ Reply to Thread
Results 1 to 9 of 9

Thread: Cron task

  1. Cron task

    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


  2. Re: Cron task

    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( ) {


    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


  3. Re: Cron task

    In article <1123534221.950972.202210@g47g2000cwa.googlegroups. com>,
    "yezi" 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( ) {
    >
    >
    > 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 " could be
    rewritten as "". 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
    -----


  4. Re: Cron task

    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.


  5. Re: Cron task

    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


  6. Re: Cron task

    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( ) {


    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


  7. Re: Cron task

    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 *****************************

  8. Re: Cron task

    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( ) {
    >
    >
    > 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......


  9. Re: Cron task

    thanks for great help


+ Reply to Thread