Ksh:Loggin StdOut/StdErr to file and screen and keep exit value

Ksh:Loggin StdOut/StdErr to file and screen and keep exit value

Post by Ben Shad » Tue, 07 Mar 2000 04:00:00



Using Ksh, I am trying to log both StdOut and StdErr to a file but keep
the exit value of the command and write it to screen.
i.e Something like the following (It is not correct and probably over
complicated)

exec 9>&1

4>&1`
exit $status

I can't seem to get it to work for with StdOut as well.

Basically I want to keep the exit value of "mycommand" and write StdOut
and StdErr to Screen and to the logfile "ErrLog".

Any suggestions for a newbee.

Ben Shade

 
 
 

Ksh:Loggin StdOut/StdErr to file and screen and keep exit value

Post by Lee A. Newcom » Tue, 07 Mar 2000 04:00:00


Have you considered just using the script(1) cmd?
E.g.:
  script $HOME/ErrLog

  print $(( Status = $? ))
  return $status

-- lan


> Using Ksh, I am trying to log both StdOut and StdErr to a file but keep
> the exit value of the command and write it to screen.
> i.e Something like the following (It is not correct and probably over
> complicated)

> exec 9>&1

> 4>&1`
> exit $status

> I can't seem to get it to work for with StdOut as well.

> Basically I want to keep the exit value of "mycommand" and write StdOut
> and StdErr to Screen and to the logfile "ErrLog".

> Any suggestions for a newbee.

> Ben Shade


 
 
 

Ksh:Loggin StdOut/StdErr to file and screen and keep exit value

Post by Ben Shad » Wed, 08 Mar 2000 04:00:00


Thanks for the suggestion - but I had already looked at using script - but it
does not really work very well inside a command file and gives a few strange
results (when I tried it).
Ben Shade
------------------------------------------------------------------------------------------

> Have you considered just using the script(1) cmd?
> E.g.:
>   script $HOME/ErrLog

>   print $(( Status = $? ))
>   return $status

> -- lan


> > Using Ksh, I am trying to log both StdOut and StdErr to a file but keep
> > the exit value of the command and write it to screen.
> > i.e Something like the following (It is not correct and probably over
> > complicated)

> > exec 9>&1

> > 4>&1`
> > exit $status

> > I can't seem to get it to work for with StdOut as well.

> > Basically I want to keep the exit value of "mycommand" and write StdOut
> > and StdErr to Screen and to the logfile "ErrLog".

> > Any suggestions for a newbee.

> > Ben Shade

 
 
 

Ksh:Loggin StdOut/StdErr to file and screen and keep exit value

Post by Matthew Land » Wed, 08 Mar 2000 04:00:00



> Using Ksh, I am trying to log both StdOut and StdErr to a file but keep
> the exit value of the command and write it to screen.
> i.e Something like the following (It is not correct and probably over
> complicated)

> exec 9>&1

> 4>&1`
> exit $status

> I can't seem to get it to work for with StdOut as well.

> Basically I want to keep the exit value of "mycommand" and write StdOut
> and StdErr to Screen and to the logfile "ErrLog".

> Any suggestions for a newbee.

> Ben Shade

how about:

(./mycommand; echo "status=$?">$HOME/stat.file)2>&1 |tee -a $HOME/ErrLog
. $HOME/stat.file
exit $status

 - Matt

--

  AIX and HACMP Certified Specialist    | |  / \ |\| |  \. ,_|    _| --
  / Comments, views, and opinions \     | |_/ ^ \|   | ) | |      \, *_)
  \ are mine alone, not IBM's.    /     |___|/~\_\_|\|__/|_|        \(

 
 
 

Ksh:Loggin StdOut/StdErr to file and screen and keep exit value

Post by Ken Pizzi » Fri, 10 Mar 2000 04:00:00



>Using Ksh, I am trying to log both StdOut and StdErr to a file but keep
>the exit value of the command and write it to screen.
>i.e Something like the following (It is not correct and probably over
>complicated)

>exec 9>&1

>4>&1`
>exit $status

>I can't seem to get it to work for with StdOut as well.

exec 3>&1
status=`exec 4>&1 1>&3 3>&-

echo $status

                --Ken Pizzini

 
 
 

1. stderr & stdout to file and stderr to screen

Within a (bash) script I want to log standard output and standard error
to a log file. Ok, I used something like

  prog >> logfile 2>&1

But now I want to see the error messages (and ONLY the error messages)
also on my screen. I think "tee" and the use of further filedescriptors
are proper tools but how it works really ?

Thanks

Jens

--
Dr. Jens Schleusener            debis Systemhaus
phone: +49 (551) 709-2493       Solutions for Research
fax:   +49 (551) 709-2169       Bunsenstr.10

2. need help / script for ibm isp

3. Matrox Mystique ands X.

4. man command

5. ksh redirect stdout & stderr > file1, stderr > file2

6. Various questions

7. redirection: stdout to one file, stderr to other file, and both to screen

8. any plugin or app similar to this ...

9. file descriptor Q, redirecting stderr and stdout to stdout and file.

10. ksh: "tee" stdout and stderr to seperate files?

11. Sending STDERR and STDOUT to screen and file?

12. Redirecting stderr & stdout to file and screen

13. Redirecting stdout and stderr to file as well as screen for Korn shell