Xref: utzoo comp.unix.questions:29741 comp.unix.shell:1745 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!princeton!phoenix.Princeton.EDU!pfalstad From: pfalstad@phoenix.Princeton.EDU (Paul Falstad) Newsgroups: comp.unix.questions,comp.unix.shell Subject: Re: What's wrong with this sh script ? Message-ID: <7489@idunno.Princeton.EDU> Date: 25 Mar 91 03:39:10 GMT References: <1991Mar25.004244.15295@noose.ecn.purdue.edu> Sender: news@idunno.Princeton.EDU Followup-To: comp.unix.questions Distribution: na Organization: League For Fighting Chartered Accountancy Lines: 42 luj@gus17.ecn.purdue.edu (Jun Lu) wrote: >Your "at" job "7148" produced the following output: > >gus ... 10:56pm up 2 days, 5:05, 1 user, load average: 5.82, 6.24, 6.34 >OK >___ > >But where is the output for 2nd machine ? ... >echo -n "$HOST ..." >if rsh -l $USER $HOST uptime >then > echo OK >else > echo died >fi The problem is that rsh eats up its standard input, which also happens to be the shell script you're executing, since at gives your script to the shell as standard input. So when you rsh to the first host, while you're waiting for uptime to execute, rsh reads its input (your shell script), and sends it over the socket. Then uptime exits without reading anything. Now when the shell wakes up and tries to read the rest of your script, it gets an EOF, since rsh has eaten up all its input. The reason that the shell managed to print the OK is because the rsh was part of a control structure; the shell read in the whole if ... fi structure before executing rsh. Nothing after the fi was executed. You can try for yourself that if you put the whole script in braces { }, forcing the shell to parse all of it before executing, it will work fine. The easiest way to fix this is just to use the -n flag of rsh. rsh -n -l $USER $HOST uptime Read the FM for more information. -- Paul Falstad, pfalstad@phoenix.princeton.edu | 10 PRINT "PRINCETON CS" [Your blood pressure just went up.] | 20 GOTO 10 Princeton University would like to apologize to everyone for this article.