Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

catch stdout and stderr of cpio 1

Status
Not open for further replies.

juergenw

MIS
Aug 21, 2000
8
DE
Hello,

I try to catch stderr and stdout from the cpio command (AIX 4.1.5.0 and sco openserver 5.0.5).
When trying
find . -print | cpio -ocvB > /dev/rmt0 2>errorlog
cpio using the verbose mode and put stderr in errlog file no displays of the cpio are made on the screen but in the errorlog file (even stdout).
When trying without the verbose mode "2>errorlog" works perfect but the user does not know, what cpio works on at the moment.

Any idea?
Thank you for help
 
Yep:
[tt]
AnyCommand 2>&1 > /file/for/stdout | tee /file/for/stderr
[/tt]

This will send the standard errors to standard output, but standard output will be sent to a file or device, and then the redirected errors will be sent to tee, and tee will write all its input to both (simultaneously) its standard output and to the named file.

I hope it works...
 
Thank your for answering, but it doesn't work.

Here's what happens: After the start of the cpio no output is displayed on the screen. Although an error should occur (uid of file htpr > 65535), file stderr is empty and the content of file stdout is not just, what normally is displayed from cpio (see below without the 2>&1 > ... term):
# find . |cpio -ocvB > /dev/rmt0 2>&1 > /usr1/jwt/stdout | tee /usr1/jwt/stderr
# l
total 136
drwxr-xr-x 2 root system 1024 Nov 23 18:30 .
drwxrwxrwx 23 bin bin 1536 Nov 03 13:43 ..
---------- 1 nobody system 768 Nov 03 14:11 htpr
-rw-r--r-- 1 root system 71 Nov 22 18:04 inhalt
-rw-r--r-- 1 root system 0 Nov 23 18:34 stderr
-rw-r--r-- 1 root system 25600 Nov 23 18:34 stdout
-rw-r--r-- 1 root system 4639 Nov 03 14:18 tape
-rwx------ 1 root system 64 Nov 03 14:19 taperestorecommand
-rw-r--r-- 1 root system 5378 Nov 03 14:19 tapeuser
-rw-r--r-- 1 root system 38 Nov 03 14:19 tapeusersel
# find . |cpio -ocvB > /dev/rmt0
.
tape
cpio: 0511-900 htpr not archived; file's uid cannot be greater
than 65535.
tapeuser
tapeusersel
stdout
inhalt
stderr
taperestorecommand
80 blocks
#

any further ideas?
 
Check if that is working:

(command > /file/for/stdout ) >& /file/for/stderr

regards
chenn
 
Thank you but it doesn't work,
I asume syntax ">& /file/for/stderr" is for csh/tcsh (see So I changed it as discribed to "prog > file 2>&1" for ksh.

( find . | cpio -ocvB > /dev/rmt0 > /usr1/jwt/stdout) > /usr1/jwt/stderr 2>&1

Problems:
1. cpio doesn't write any data on /dev/rmt0 (see 4.)
2. no display is made on screen (because of 2>&1. I want to have output on screen and in stdout logfile).
3. in stderr file are messages from stderr and stdout.
4. stdout file consists of messages which are usually not displayed (looks like it gets input from cpio which should be on tape).
 
Have you tried using [tt]pax[/tt]? You can write CPIO files with [tt]pax[/tt], you can use the [tt]-x cpio[/tt] option to write CPIO formatted archive files... and you can use the [tt]-f /archive/file[/tt] option and then you don't need tricky redirections!.
 
ok. I haven't used pax before, but after having an eye on several manuals it seems to me, that pax is not able to backup a list of files coming from an find f.e.

find . \( \! -name "*.d*" \! -name "*.b*" \! -name "*.lk" \! -name "
lbi*" \! -name "srt*" \! -name "pge*" \! -name "core*" \! -name "*.LOG" \) -prinz
t | pax -wvf /dev/rmt0 -x cpio -b 512b

I tried it but it doesn't work this way. (and I'm back at the crazy cpio problem).
I'm a wrong?
Thanks
 
The first command you showed

find . -print | cpio -ocvB > /dev/rmt0 2>errorlog

is working exactly as you wrote it. I think what you are wanting to do is split errors from what you think is standard output (-v), correct? If so, cpio won't let you do it since it uses stdout/stderr in an odd-ball way.

cpio uses stdout not for displaying normal things to the screen, but for dumping the output (in your case to /dev/rmt0) of a -o option. All "screen" output, whether errors or -v induced, goes to stderr.

The only way to split out errors vs -v stuff would be to pass the output to a script and have the script figure out the difference between the two.
 
Your right with your suggestion, Gary. I want to have stderr messages in one logfile because it's much more easy if a customer has backup problems to have just one look in one errorlog file than having a look through complete stdout (2>&1) of the backup. And with several hundreds of unix-servers running all over the world doing backup every night you can imagine how much time this would save having detailed errorlogs.

Finally I made another test on pax.
Even if stdout is redirected on a stdout file it is empty.

# pax -wvf /dev/rmt0 -b 512b `echo *` 1>stdout 2>stderr
# l stdout
-rw-r--r-- 1 root system 0 Nov 28 13:09 stdout
# cat stderr
cleart
pax: htpr : User ID is too large and will be truncated
htpr

All output from -v is made through stderr (when using -x cpio, too) which means I'm not able to redirect all errors in a single errorlog file without having the normal stdout in between.
So I have no other chance than passing the output to a script as you suggested.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top