Operating System - HP-UX
1821188 Members
3333 Online
109631 Solutions
New Discussion юеВ

Re: perl script and tee failure

 
SOLVED
Go to solution
jerry1
Super Advisor

perl script and tee failure

I have a ksh script that runs a perl script
ftp module in it.

I am trying to use tee to get output from
perl script:

#!/bin/ksh
.
.
perlscript.pl | tee -a ./logfile.


The output does not go to logfile.
cron however does email me the perl output
I want. What's wrong with tee here?

The perl script is using the perl Net::FTP
module if that makes any difference.
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor
Solution

Re: perl script and tee failure

Hi Jerry:

The output you see is probably going to STDERR. Do this:

# script >2&1 | tee logfile

Regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor

Re: perl script and tee failure

Of course he means:

# script 2>&1 | tee logfile

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
James R. Ferguson
Acclaimed Contributor

Re: perl script and tee failure

Hi Merijn:

YES! I (of course) do mean that!

# script 2>&1 | tee logfile

Thanks (and warm regards)!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: perl script and tee failure

I just ran a Perl script under ksh using Net::FTP and piped to tee -a xxx and the output was sent to stdout and to the file xxx just as expected. Is your Perl script interactive? If so there may be a problem with the redirection of stdin. My particular Perl script just processed command-line args and worked perfectly. One other thought is that your Perl script might itself be redirecting stdout so that tee sees nothing on its stdin.
If it ain't broke, I can fix that.
jerry1
Super Advisor

Re: perl script and tee failure

I don't know why but 2>&1 works.
I get stderr to console and logfile. ???

Why does Clays work okay.??

Here is the ksh script.

#!/bin/ksh

test.pl | tee -a a.out

Here is the perl code.

#!/usr/bin/perl

use strict;
use warnings;
use Net::FTP;
use Net::Netrc;
my $server="appsvr2";
my $file="testfile";
my $destination = "/tmp";
my $pageid = "sysadmins";
my $pager = "/usr/local/bin/pager";
my $ftpid = "user1";
my $pass = "pass12";

my $ftp = Net::FTP->new ($server, Timeout => 9000, Debug => 3) or die (exec "$pager $pageid \"$server: ftp AP cannot connect: $@\"") ;

$ftp->login("$ftpid","$pass") or die (exec "$pager $pageid \"ftp AP cannot login.\"") ;

$ftp->binary or die (exec "$pager $pageid \"ftp AP failed binary mode.\"") ;

#$ftp->cwd ($destination) or die (exec "$pager $pageid \"ftp AP failed cwd.\"") ;

$ftp->put ($file) or die (exec "$pager $pageid \"ftp AP cannot put file. \"") ;

$ftp->ls ($file) or die (exec "$pager $pageid \"ls of AP file failed. \"") ;

$ftp->quit;

# If we get this far then everything should be okay. Send notice to requestor.

my $uid=(stat ("testfile"))[4];
my $name=getpwuid ($uid);
open OU,"|mailx -s \"AP file sent\" $name";
open IN,"/tmp/runap.data";
print OU $_ while ;





James R. Ferguson
Acclaimed Contributor

Re: perl script and tee failure

Hi Jerry:

I believe the difference is in the 'Debug' value you have specified. Non-zero values, cause all commands and responses to be sent to STDERR. Thus, 'cron' would take this output and email it to you, but your script (without the redirection I suggested) would not have routed its output to your logfile.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: perl script and tee failure

Actually the answer is even simpler. After examining your Perl script, you don't have any statements which output to stdout and thus tee see's no input. The only output which MIGHT go to your terminal is stderr and tee doesn't read that. Only when both stderr and stdout are sent to fdes 1 (stdout) does tee see any input. This was a simple case of that stupid computer doing exactly what it was told to do.
If it ain't broke, I can fix that.