comp.unix.shell:
> Hi, I have a textfile storing a hostname. Now how do I grab the
> hostname from the file and input it to the rsh command. I try the
> following but it does not work:
> cat filename | rsh command
Whatever it is you are trying, this is a Useless Use of Cat.
Read up on this fascinating topic: <http://www.iki.fi/era/unix/award.html>
If you are trying to get rsh to connect to the host named in filename,
this is the wrong way to go about it. Rsh can only accept the host
name as its first command line parameter -- definitely not on standard
input.
Here are a few suggestions:
rsh `cat filename` command
while read host; do rsh $host command ; done <filename
xargs -n 1 -i rsh {} command <filename
sed -e 's/.*/rsh & command/' filename | sh
The first two are probably closest to what you want, but it depends on
what you're trying to do which is better. The latter two are slightly
tricky, but if you have the time, it might be fun to try to figure
them out. (It's not like they're rocket science or anything, but I'm
guessing you might not have stumbled over these constructs.)
Incidentally, if you play around, try substituting "echo" for "rsh"
since it accepts the same sorts of thingies as command line
parameters, but will tell you what exactly it's doing (and won't hang
mysteriusly if you somehow invoke it with slightly wrong parameters).
Then when you get what you expect, switch back. "Try before you buy"
is a great way to improve your programs.
I have omitted defensive quoting in the interest of clarity. If the
file might contain arbitrary text, you have to be more careful.
> Please help!!!!!!!
Your exclamation mark key seems to be hung.
Hope this helps,
/* era */
--
Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition