Re: Redirect stdout, stderr to file and stdout

2004-01-16 Thread drieux
On Jan 16, 2004, at 5:02 PM, Larry Guest wrote:

I have a small script that does some admin work for me.

What I need to do now is not only have is display information to STDERR
and STDOUT but also write the same information I see when I run the
command to a file.
I have written it for others who are not very technical.  I want them 
to
be able to see the script working and what it is doing.  But I also 
need
a log file of the same information so I can have it mailed to me and
keep a copy on the server.
Here's a bit of a wacky Idea - solve it by
a bit of indirection - namely write the
code so that it does what you want it to do
then nest it inside of a script like say
	#!/bin/sh

	myPerlCode 2>&1 | tee /tmp/myOutput.$$

mail me -s "command run" < /tmp/myOutput.$$
/bin/rm -f /tmp/myOutput.$$
that way your perl code remains simple, but what you
hand out to the users to use is going to deal with
all of the STDOUT|STDERR as well a always sending
you the email...
ciao
drieux
---

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Redirect stdout, stderr to file and stdout

2004-01-16 Thread Tim Johnson

One quick and dirty solution that I've used for some debugging in the
past is to create a subroutine called PrintOut();


###

use strict;
use warnings;

open(OUTFILE,">mylog.txt") || die;
PrintOut("Hello World\n");

sub PrintOut{
   print @_;
   print OUTFILE @_;
}
 
###

-Original Message-
From: Larry Guest [mailto:[EMAIL PROTECTED] 
Sent: Friday, January 16, 2004 5:03 PM
To: [EMAIL PROTECTED]
Subject: Redirect stdout, stderr to file and stdout


What I need to do now is not only have is display information to STDERR
and STDOUT but also write the same information I see when I run the
command to a file.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Redirect stdout, stderr to file and stdout

2004-01-16 Thread Paul Johnson
On Fri, Jan 16, 2004 at 05:02:52PM -0800, Larry Guest wrote:

> I have a small script that does some admin work for me.
> 
> What I need to do now is not only have is display information to STDERR
> and STDOUT but also write the same information I see when I run the
> command to a file.
> 
> I have written it for others who are not very technical.  I want them to
> be able to see the script working and what it is doing.  But I also need
> a log file of the same information so I can have it mailed to me and
> keep a copy on the server.
> 
> I cant seem to get this to work.

You don't say what OS you are on, but on *nix I would do something like:

$ perl -le 'print STDERR "stderr"; print "stdout"' 2>&1 | tee output.txt

Solutions in Perl take more effort, but we can discuss them if necessary.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Redirect stdout, stderr to file and stdout

2004-01-16 Thread John McKown
On Fri, 16 Jan 2004, Larry Guest wrote:

> I have a small script that does some admin work for me.
> 
> What I need to do now is not only have is display information to STDERR
> and STDOUT but also write the same information I see when I run the
> command to a file.
> 
> I have written it for others who are not very technical.  I want them to
> be able to see the script working and what it is doing.  But I also need
> a log file of the same information so I can have it mailed to me and
> keep a copy on the server.
> 
> I cant seem to get this to work.
> 

What have you tried? I would alter the script to have multiple print 
statements. One to STDERR or STDOUT, the other to my file. Something like:

open(LOGGER,'myfile.log');
...
print STDERR "$message\n";
print LOGGER "$message\n";
...

If you want, you could "encapsulate" this by not using print directly, but 
in your own function, say "myprint()".

sub myprint {
my $fn = shift;
print $fn "@_";
print LOGGER "@_";
}

my $STDOUT=\STDOUT;
my $STDERR=\STDERR;
...
my $message="This is a test.\n";
...
&myprint($STDOUT,$message);
...
&myprint($STDERR,$message);

Hope this is useful in some way.

--
Maranatha!
John McKown


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Redirect stdout, stderr to file and stdout

2004-01-17 Thread Randal L. Schwartz
> "Larry" == Larry Guest <[EMAIL PROTECTED]> writes:

Larry> I have a small script that does some admin work for me.
Larry> What I need to do now is not only have is display information to STDERR
Larry> and STDOUT but also write the same information I see when I run the
Larry> command to a file.

Larry> I have written it for others who are not very technical.  I want them to
Larry> be able to see the script working and what it is doing.  But I also need
Larry> a log file of the same information so I can have it mailed to me and
Larry> keep a copy on the server.

Larry> I cant seem to get this to work.

I think this might do it:

open TEE, "| tee YourLogFileHere";
open STDOUT, ">&TEE";
open STDERR, ">&TEE";

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Redirect stdout, stderr to file and stdout

2004-01-18 Thread Larry Guest
This is very close.

But the script hangs and wont exit the "tee" command.

I ran the script using "strace" and it sits there like this.

write(1, "Backup and Replication is comple"..., 65Backup and Replication
is complete for mysite.com
) = 65
close(3)= 0
munmap(0x401fd000, 4096)= 0
rt_sigaction(SIGHUP, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGINT, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL}, 8) = 0
wait4(3576, 



And a ps-ef looks like this.

root  3576  3575  0 02:19 pts/000:00:00 tee YourLogFileHere

I have a close (TEE); at the end as well.

Any thoughts?

Thanks

-Original Message-
From: Randal L. Schwartz [mailto:[EMAIL PROTECTED] 
Sent: Saturday, January 17, 2004 9:55 AM
To: [EMAIL PROTECTED]
Subject: Re: Redirect stdout, stderr to file and stdout


>>>>> "Larry" == Larry Guest <[EMAIL PROTECTED]> writes:

Larry> I have a small script that does some admin work for me. What I 
Larry> need to do now is not only have is display information to STDERR 
Larry> and STDOUT but also write the same information I see when I run 
Larry> the command to a file.

Larry> I have written it for others who are not very technical.  I want 
Larry> them to be able to see the script working and what it is doing.  
Larry> But I also need a log file of the same information so I can have 
Larry> it mailed to me and keep a copy on the server.

Larry> I cant seem to get this to work.

I think this might do it:

open TEE, "| tee YourLogFileHere";
open STDOUT, ">&TEE";
open STDERR, ">&TEE";

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095 <[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See
PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!

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




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




RE: Redirect stdout, stderr to file and stdout

2004-01-18 Thread Larry Guest
I think I have it.

I had to have

close (STDERR)
close (STDOUT)
close (TEE)

-Original Message-
From: Larry Guest [mailto:[EMAIL PROTECTED] 
Sent: Saturday, January 17, 2004 11:22 PM
To: 'Randal L. Schwartz'; [EMAIL PROTECTED]
Subject: RE: Redirect stdout, stderr to file and stdout


This is very close.

But the script hangs and wont exit the "tee" command.

I ran the script using "strace" and it sits there like this.

write(1, "Backup and Replication is comple"..., 65Backup and Replication
is complete for mysite.com
) = 65
close(3)= 0
munmap(0x401fd000, 4096)= 0
rt_sigaction(SIGHUP, {SIG_IGN}, {SIG_DFL}, 8) = 0 rt_sigaction(SIGINT,
{SIG_IGN}, {SIG_DFL}, 8) = 0 rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL},
8) = 0 wait4(3576, 



And a ps-ef looks like this.

root  3576  3575  0 02:19 pts/000:00:00 tee YourLogFileHere

I have a close (TEE); at the end as well.

Any thoughts?

Thanks

-Original Message-
From: Randal L. Schwartz [mailto:[EMAIL PROTECTED] 
Sent: Saturday, January 17, 2004 9:55 AM
To: [EMAIL PROTECTED]
Subject: Re: Redirect stdout, stderr to file and stdout


>>>>> "Larry" == Larry Guest <[EMAIL PROTECTED]> writes:

Larry> I have a small script that does some admin work for me. What I
Larry> need to do now is not only have is display information to STDERR 
Larry> and STDOUT but also write the same information I see when I run 
Larry> the command to a file.

Larry> I have written it for others who are not very technical.  I want
Larry> them to be able to see the script working and what it is doing.  
Larry> But I also need a log file of the same information so I can have 
Larry> it mailed to me and keep a copy on the server.

Larry> I cant seem to get this to work.

I think this might do it:

open TEE, "| tee YourLogFileHere";
open STDOUT, ">&TEE";
open STDERR, ">&TEE";

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095 <[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See
PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!

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




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




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




Re: Redirect stdout, stderr to file and stdout

2004-01-20 Thread Jenda Krynicky
From: "Larry Guest" <[EMAIL PROTECTED]>
> What I need to do now is not only have is display information to
> STDERR and STDOUT but also write the same information I see when I run
> the command to a file.

Strange you only got a few Unix-only solutions when there are at 
least two modules that do this on any OS at all.

See IO::Tee on CPAN or Local::TeeOutput on http://Jenda.Krynicky.cz

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]