Professional Web Applications Themes

Expect prog. doesn't work in background ! - PERL Beginners

All. I wrote this perl program using Expect.pm and this program also works fine in foreground but does NOT work in background (cron job). Any help is greatly appreciated. Thanks #!/usr/local/bin/perl -w use File::Basename; our $debug; use Expect; ARGV == 1 or die "usage: $0 rem_host rem_user rem_pswd lcal_file rem_file\n"; my ($rem_host, $rem_user, $rem_pswd, $lcal_file, $rem_file) = split ':', shift; die "usage: $0 rem_host:rem_user:rem_pswd:lcal_file:rem_file" unless defined $rem_host; my $t = 30; my $ftp_prompt = 'ftp> '; if ($debug) { $Expect::Debug=1; $Expect::Exp_Internal=1; } my $ftp = Expect->spawn ("ftp", $rem_host); $ftp->expect($t, "Name") or die "Never got username prompt on $host, " . ...

  1. #1

    Default Expect prog. doesn't work in background !

    All.

    I wrote this perl program using Expect.pm and this program also works
    fine in foreground but does NOT work in background (cron job). Any help
    is greatly appreciated.

    Thanks

    #!/usr/local/bin/perl -w

    use File::Basename;
    our $debug;
    use Expect;
    ARGV == 1 or die "usage: $0 rem_host rem_user rem_pswd lcal_file
    rem_file\n";
    my ($rem_host, $rem_user, $rem_pswd, $lcal_file, $rem_file) = split ':',
    shift;
    die "usage: $0 rem_host:rem_user:rem_pswd:lcal_file:rem_file" unless
    defined $rem_host;

    my $t = 30;
    my $ftp_prompt = 'ftp> ';
    if ($debug) {
    $Expect::Debug=1;
    $Expect::Exp_Internal=1;
    }

    my $ftp = Expect->spawn ("ftp", $rem_host);
    $ftp->expect($t, "Name") or die "Never got username prompt on $host, " .
    $ftp->exp_error() . "\n";
    print $ftp "$rem_user\r";

    $ftp->expect($t, '-re', 'Password:\s*') or die "Never got password
    prompt on $host, " . $ftp->exp_error() . "\n";
    print $ftp "$rem_pswd\r";

    $ftp->expect($t, '-re', $ftp_prompt) or die "Never got ftp prompt after
    sending username and password, " .$ftp->exp_error() . "\n";
    print $ftp "bin\r";

    $ftp->expect($t, '-re', $ftp_prompt) or die "Never got ftp prompt after
    switch to bin format, " . $ftp->exp_error() . "\n";
    print $ftp "send $lcal_file $rem_file\r";

    $ftp->expect($t, '-re', $ftp_prompt) or die "Never got ftp prompt after
    sending file, " . $ftp->exp_error() . "\n";
    print $ftp "quit\r";
    $ftp->expect($t, '-re', "Goodbye.") or die "Never got 'Goodbye.', " .
    $ftp->exp_error() . "\n";
    $ftp->hard_close();


    Ravinder Guest

  2. #2

    Default Re: Expect prog. doesn't work in background !

    Ravinder Arepally wrote: 

    Try using full paths to external programs. Cron doesn't always set a usable PATH
    when it runs scripts.

    --
    Andrew Gaffney
    Network Administrator
    Skyline Aeronautics, LLC.
    636-357-1548

    Andrew Guest

  3. #3

    Default RE: Expect prog. doesn't work in background !


    It works from command line. Problem is when we run it as a cron job.

    -----Original Message-----
    From: Andrew Gaffney [mailto:com]
    Sent: Thursday, July 15, 2004 12:57 PM
    To: beginners
    Subject: Re: Expect prog. doesn't work in background !

    Ravinder Arepally wrote: 

    Try using full paths to external programs. Cron doesn't always set a
    usable PATH when it runs scripts.

    --
    Andrew Gaffney
    Network Administrator
    Skyline Aeronautics, LLC.
    636-357-1548


    --
    To unsubscribe, e-mail: org
    For additional commands, e-mail: org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Ravinder Guest

  4. #4

    Default Re: Expect prog. doesn't work in background !

    Ravinder Arepally wrote: 

    Yes, because you have a good PATH set at the command line. Not all cron daemons
    will set a sensible PATH environment variable. Use full paths to executables in
    your perl program. For example, use '/usr/bin/ftp' (or whatever) instead of 'ftp'.

    --
    Andrew Gaffney
    Network Administrator
    Skyline Aeronautics, LLC.
    636-357-1548

    Andrew Guest

Similar Threads

  1. Replies: 4
    Last Post: September 19th, 10:27 AM
  2. css background doesn't appear in web browser
    By xen1 in forum Macromedia Dynamic HTML
    Replies: 7
    Last Post: August 28th, 05:27 PM
  3. Replies: 1
    Last Post: January 28th, 02:09 PM

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