caturing ftp standard output while using system() and cron

Discussion in 'Perl Misc' started by Nathan Pryor, Sep 11, 2003.

  1. Nathan Pryor

    Nathan Pryor Guest

    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
    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, Sep 11, 2003
    #1
    1. Advertising

  2. Nathan Pryor

    Thens Guest

    On 11 Sep 2003 09:17:31 -0700
    (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, Sep 11, 2003
    #2
    1. Advertising

  3. On 11 Sep 2003 09:17:31 -0700
    (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. http://www.gnu.org/licenses/gpl.txt
    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, Sep 11, 2003
    #3
  4. Nathan Pryor

    Dave Saville Guest

    On Thu, 11 Sep 2003 21:53:51 +0530, Thens wrote:

    >On 11 Sep 2003 09:17:31 -0700
    > (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, Sep 11, 2003
    #4
  5. Nathan Pryor

    Tintin Guest

    "Dave Saville" <> wrote in message
    news:...
    > On Thu, 11 Sep 2003 21:53:51 +0530, Thens wrote:
    >
    > >On 11 Sep 2003 09:17:31 -0700
    > > (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 http://search.cpan.org/
    Tintin, Sep 12, 2003
    #5
  6. Nathan Pryor

    Nathan Pryor Guest

    <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 http://search.cpan.org/


    I'm looking at the module now. Thanks for the tip everyone.
    Nathan Pryor, Sep 12, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. baytes

    Cron Job Output

    baytes, Dec 2, 2009, in forum: Python
    Replies:
    1
    Views:
    335
    LoD MoD
    Dec 3, 2009
  2. Daniel Berger

    net/ftp works manually, fails via cron

    Daniel Berger, Sep 23, 2005, in forum: Ruby
    Replies:
    3
    Views:
    111
    Daniel Berger
    Sep 23, 2005
  3. Venks
    Replies:
    5
    Views:
    237
    Ken Bloom
    Dec 6, 2007
  4. D. Buck
    Replies:
    2
    Views:
    479
    D. Buck
    Jun 29, 2004
  5. Bill H

    Ftp via Perl cron job

    Bill H, Sep 26, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    189
    J. Gleixner
    Sep 28, 2006
Loading...

Share This Page