caturing ftp standard output while using system() and cron

N

Nathan Pryor

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 (e-mail address removed)
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
 
T

Thens

On 11 Sep 2003 09:17:31 -0700
(e-mail address removed) (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.
 
J

James Willmore

On 11 Sep 2003 09:17:31 -0700
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 ;)

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
 
D

Dave Saville

On 11 Sep 2003 09:17:31 -0700
(e-mail address removed) (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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top