caturing ftp standard output while using system() and cron

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default caturing ftp standard output while using system() and cron

    I need to capture all standard output of an ftp session that is run
    inside a perl program. Short example:

    #!/usr/bin/perl
    system("ftp -i ftp.gnu.org > results");

    I use a .netrc file to list the commands for the ftp session:

    machine ftp.gnu.org
    login anonymous
    password [email]mrtortoise@yahoo.com[/email]
    macdef init
    lcd /tmp
    ls
    pwd
    bye

    I have no problems capturing all standard output, both local and
    remote, when I run the script from the command line. However, when I
    run the script using a cron job only the standard output from the
    remote host shows up in the file. In my real script I am using "mput"
    to send several files to the remote host so I need to see the local
    standad output in order to verify all files transferred successfully.
    Any suggestions?

    Perl version: This is perl, v5.6.1 built for i386-linux
    Nathan Pryor Guest

  2. Similar Questions and Discussions

    1. Some 'System Calls' was Capturing system call output value
      On Friday, Nov 14, 2003, at 18:39 US/Pacific, Jerry Rocteur wrote: Wiggins is the one who deserves the point, since he was the one with the...
    2. Capturing system call output value
      perldoc -q 'output of a command' You want backticks instead, though there are better ways to come by the sysem name, and don't use $a.... ...
    3. Help with "A specified file does not support the ioctl system call." in cron
      david.n.moreno@lmco.com (Dave Moreno) writes: Without seeing a copy of the script, I'm not sure anyone will be able to assist you. Best...
    4. Ncurses output started from cron
      Dear Charles, just an idea: what if you use "expect" within a shell- script that has been started by cron??? An idea, nothing more, nothing less...
    5. system has started e-mailing me, cron demon
      Hello, I have started to get the following message e-mailed to me at night. Envelope-to: web@debian From: root@debian (Cron Daemon) To:...
  3. #2

    Default Re: caturing ftp standard output while using system() and cron

    On 11 Sep 2003 09:17:31 -0700
    [email]mrtortoise@yahoo.com[/email] (Nathan Pryor) wrote:

    # I need to capture all standard output of an ftp session that is run
    # inside a perl program. Short example:
    #
    # #!/usr/bin/perl
    # system("ftp -i ftp.gnu.org > results");

    Why dont you use Net::FTP and save yourself the trouble of Portability
    and other issues.

    The thumb rule is use perl modules wherever you can.

    Regards,
    Thens.

    Thens Guest

  4. #3

    Default Re: caturing ftp standard output while using system() and cron

    On 11 Sep 2003 09:17:31 -0700
    [email]mrtortoise@yahoo.com[/email] (Nathan Pryor) wrote:
    > I need to capture all standard output of an ftp session that is run
    > inside a perl program. Short example:
    >
    > #!/usr/bin/perl
    > system("ftp -i ftp.gnu.org > results");
    You're redirecting STDOUT to a file ('>') - use 'tee' to see both
    STDERR and STDOUT -and- redirect STDOUT to a file ;)

    <snip>
    > I have no problems capturing all standard output, both local and
    > remote, when I run the script from the command line. However, when
    > I run the script using a cron job only the standard output from the
    > remote host shows up in the file. In my real script I am using
    > "mput" to send several files to the remote host so I need to see the
    > local standad output in order to verify all files transferred
    > successfully. Any suggestions?
    <snip>

    perldoc -q "Why can't I get the output of a command with system()?"
    perldoc -q "How can I capture STDERR from an external command?"

    So, basically, you could do ...
    ==untested==
    #notice there's no '> results'
    open(CMD, "ftp -i ftp.gnu.org |");
    my @results = <CMD>;
    close CMD;

    You could also look at the Net::FTP module ;)

    HTH

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. [url]http://www.gnu.org/licenses/gpl.txt[/url]
    for more information.

    a fortune quote ...
    A language that doesn't have everything is actually easier to
    program in than some that do. -- Dennis M. Ritchie
    James Willmore Guest

  5. #4

    Default Re: caturing ftp standard output while using system() and cron

    On Thu, 11 Sep 2003 21:53:51 +0530, Thens wrote:
    >On 11 Sep 2003 09:17:31 -0700
    >mrtortoise@yahoo.com (Nathan Pryor) wrote:
    >
    ># I need to capture all standard output of an ftp session that is run
    ># inside a perl program. Short example:
    >#
    ># #!/usr/bin/perl
    ># system("ftp -i ftp.gnu.org > results");
    >
    > Why dont you use Net::FTP and save yourself the trouble of Portability
    >and other issues.
    >
    > The thumb rule is use perl modules wherever you can.
    Assuming you know that there *is* one :-)

    Regards

    Dave Saville

    NB switch saville for nospam in address


    Dave Saville Guest

  6. #5

    Default Re: caturing ftp standard output while using system() and cron


    "Dave Saville" <dave.nospam@ntlworld.com> wrote in message
    news:qnirfnivyyragyjbeyqpbz.hl2m0um.pminews@text.n ews.ntlworld.com...
    > On Thu, 11 Sep 2003 21:53:51 +0530, Thens wrote:
    >
    > >On 11 Sep 2003 09:17:31 -0700
    > >mrtortoise@yahoo.com (Nathan Pryor) wrote:
    > >
    > ># I need to capture all standard output of an ftp session that is run
    > ># inside a perl program. Short example:
    > >#
    > ># #!/usr/bin/perl
    > ># system("ftp -i ftp.gnu.org > results");
    > >
    > > Why dont you use Net::FTP and save yourself the trouble of Portability
    > >and other issues.
    > >
    > > The thumb rule is use perl modules wherever you can.
    >
    > Assuming you know that there *is* one :-)
    Hence the reason everyone uses [url]http://search.cpan.org/[/url]


    Tintin Guest

  7. #6

    Default Re: caturing ftp standard output while using system() and cron

    <snip>
    > > >
    > > > Why dont you use Net::FTP and save yourself the trouble of Portability
    > > >and other issues.
    > > >
    > > > The thumb rule is use perl modules wherever you can.
    > >
    > > Assuming you know that there *is* one :-)
    >
    > Hence the reason everyone uses [url]http://search.cpan.org/[/url]
    I'm looking at the module now. Thanks for the tip everyone.
    Nathan Pryor Guest

Posting Permissions

  • You may not post new threads
  • You may 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