Why doesn't this work?

der Mouse mouse at thunder.mcrcim.mcgill.edu
Mon Jul 1 10:53:04 AEST 1991


In article <15679 at ccncsu.ColoState.EDU>, hallt at handel.CS.ColoState.Edu (Tim C. Hall) writes:

> ruptime | grep up | awk '{ print $1 }' | xargs -i -t remsh {} cat /log

> Using the -t option of xargs, it echoes the first command formed by
> the first "up" host listed in the ruptime, then runs that command.
> However, it drops me back into the shell after executing with only
> the first host, it doesn't substitute the remainder of the hosts
> coming through the pipe.  Why?

Good question.

> Running this command without the xargs portion yields a list of all
> our "up" hosts, delimited by a carriage return.

More likely a newline....

The most probable thing that comes to mind is that the remsh command
being run by xargs inhereits xargs' stdin.  And on the assumption that
remsh is something like the Berkeley rsh, it doesn't realize that cat
isn't interested in reading input, so it copies from its stdin to cat's
stdin.  Then cat dies, remsh exits, and the other hostnames get dropped
when the pipe's buffer is thrown away ('cause cat never read it).

If remsh has an option like rsh's -n option, to effectively redirect
stdin from /dev/null, use that.  If xargs runs a shell to execute the
command, you may be able to do

	.... | xargs -i -t remsh {} cat /log \< /dev/null

Based on an experiment with sh here, you may also be able to do

	.... | xargs -i -t sh -c 'remsh $0 cat /log </dev/null' {}

or something similar.

If none of those work, you may have to write a script file, something
like

	% cat catlog
	remsh $1 cat /log < /dev/null

and then

	.... | xargs -i -t catlog {}

					der Mouse

			old: mcgill-vision!mouse
			new: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.unix.questions mailing list