Professional Web Applications Themes

Cron task - Linux / Unix Administration

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

Sponsored Links
  1. #1

    Default 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

    Sponsored Links
    yezi Guest

  2. #2

    Default Re: Cron task

    On 8 Aug 2005 10:42:23 -0700, yezi
    <com> wrote: 
    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.
    Bill Guest

  3. #3

    Default 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( <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

    yezi Guest

  4. #4

    Default Re: Cron task

    In article <googlegroups.com>,
    "yezi" <com> writes: 

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

    Robert Guest

  5. #5

    Default 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.

    yezi Guest

  6. #6

    Default Re: Cron task

    On 8 Aug 2005 15:10:42 -0700, yezi wrote: 

    Yes. Go back and fully qualify each system call app, examples:
    /usr/sbin/tcpdump
    /bin/rm

    Bit Guest

  7. #7

    Default 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( <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

    yezi Guest

  8. #8

    Default Re: Cron task

    On 8 Aug 2005 15:55:43 -0700, yezi wrote: 

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

  9. #9

    Default Re: Cron task

    On Mon, 08 Aug 2005 15:55:43 -0700, yezi wrote:
     
    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......

    Liam Guest

  10. #10

    Default Re: Cron task

    thanks for great help

    yezi Guest

Similar Threads

  1. Help with cron
    By Chris in forum Ubuntu
    Replies: 13
    Last Post: September 14th, 06:33 PM
  2. cron
    By Anthony in forum Sun Solaris
    Replies: 7
    Last Post: August 27th, 12:28 PM
  3. Cannot End Task w/Task Manager
    By Gloria Mc in forum Windows XP/2000/ME
    Replies: 0
    Last Post: July 10th, 12:20 AM
  4. block "new task" on task manager
    By ab in forum Windows Setup, Administration & Security
    Replies: 1
    Last Post: July 1st, 01:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139