Operating System - HP-UX
1833770 Members
2168 Online
110063 Solutions
New Discussion

Re: fbackup returncode with a pipe

 
SOLVED
Go to solution
Wessel Baptist
Advisor

fbackup returncode with a pipe

When I submit "commandA pipe commandB" are there any possibilities to see the returncode of commandA?
What am I doing?
fbackup -v | tee logfile
After completion of fbackup I want to know the returncode of fbackup.

Thanks so far.
Wessel
logics take you from A to B, imagination takes you anywhere
11 REPLIES 11
Stefan Farrelly
Honored Contributor

Re: fbackup returncode with a pipe


Instead of doing fbackup | tee
you can do;

#!/bin/sh
exec 1> 2>&1
fbackup ....
echo $?

Now you can still get full log output to logfile and still pick up and process the return code from fbackup.
Im from Palmerston North, New Zealand, but somehow ended up in London...
federico_3
Honored Contributor

Re: fbackup returncode with a pipe

echo $?
I'll do a script like this:

exec 1 > /tmp/logfile 2>&1
fbackup ....................
echo $?
Wessel Baptist
Advisor

Re: fbackup returncode with a pipe

Hi,

this is not what I'm looking for.
I like to the output of fbackup on screen, so I can see the progress of fbackup, therefore I use -v switch and at the same time I want to log every fbackup-message.
And after fbackup has finished I want to test the returncode of fbackup.
If returncode is not equal to zero I want to look in the logfile for "serious" messages.
logics take you from A to B, imagination takes you anywhere
James R. Ferguson
Acclaimed Contributor

Re: fbackup returncode with a pipe

Hi Wessel:

You CAN achieve exactly what you are seeking by using the scheme below. For simplicity, I have placed elipses ("...") in place of the options to 'fbackup':

# ( fbackup ... 2>&1 ; echo $? > /tmp/fb.xit ) | tee -ia /tmp/fb.log

# EXITV=`< /tmp/fb.xit`

# if [ $EXITV -eq 0 ]...

...JRF...
Wessel Baptist
Advisor

Re: fbackup returncode with a pipe

Hi James,

the "tee" in the 1st line, "tee's" only the results of the "echo $? > file". So the result of "tee -ia file" is an emty file.
Do you have any alternatives.

Thanks, Wessel

logics take you from A to B, imagination takes you anywhere
James R. Ferguson
Acclaimed Contributor

Re: fbackup returncode with a pipe

Hi Wessel:

Sorry, I lifted some of my code out of context. Try this:

# ( fbackup ... 2>&1 ; echo $? > /tmp/fb.xit ) | tee -ia /tmp/fb.log

# EXITV=`cat /tmp/fb.xit`

# if [ $EXITV -eq 0 ]...

...JRF...
Vincent Stedema
Esteemed Contributor

Re: fbackup returncode with a pipe

Hi Wessel,

Here's some sample perl code that can be used to send output from within a script to multiple file handles:

#!/usr/bin/perl -w

# save the old file handle for STDERR
open(OLDERR, ">&STDERR");

# create some new ones to send output to
# screen and log file
open(OUTFILE, "| tee fbackup.log");
open(STDERR, ">&OUTFILE");
select(OUTFILE);

# send output to tee pipe
$result=system("fbackup ...");

# close output to tee pipe
close(STDERR);
close(OUTFILE);

# send output to STDOUT
select(STDOUT);
# re-attach STDERR
open(STDERR, ">&OLDERR");

if(!$result) {

... your code here ...
}

Hope this works :-)

Vincent
Wessel Baptist
Advisor

Re: fbackup returncode with a pipe

Hi Vincent,

I found perl in /usr/contrib/bin and I've tried your script and this works. Now I have the same output on screen as wel as in a file. Thanks a lot.
B.t.w. where can I find information / manuals over perl. I don't know anything about perl.
logics take you from A to B, imagination takes you anywhere
Vincent Stedema
Esteemed Contributor

Re: fbackup returncode with a pipe

Hi,

The No. 1 resource is http://www.cpan.org

AFAIK, the perl version shipped with HP-UX 11.00 is 4.??, which is not as powerful as the more recent versions (5.*). You'll find a depot for a more recent version at http://hpux.tn.tudelft.nl/hppd/hpux/Languages/perl-5.6.1/ .

Regards,

Vincent
Wessel Baptist
Advisor

Re: fbackup returncode with a pipe

I took another look and the solution of James R. Ferguson is exactly what I needed.
Thanks
Wessel
logics take you from A to B, imagination takes you anywhere
James R. Ferguson
Acclaimed Contributor
Solution

Re: fbackup returncode with a pipe

Hi Wessel:

Thank you very much! And, thanks for taking the time to track this thread down to say so. You make it all worthwhile.

With my warmest regards, Jim.

...JRF...