Exec command - different output

Hi Guys, I am trying to to execute the below script in two different machines

#!/bin/ksh
###############################################################################
# File : pause
###############################################################################
print "\nPlease Press \033[4m\033[0m to continue\c"
read answer

Its resulting the below output.

prem@host1:exec pause 2>> /tmp/prem.log
Please Press <Enter> to continue Connection to host1 closed.
prem@host1:
prem@host2:exec pause 2>> /tmp/prem.log
Please Press<Enter>  to continue
Connection to host2 closed.
prem@host2:

. When I execute the command in host1 its not waiting for input. Any idea friends? Thanks Prem

Is this Solaris? Are the two servers are of same *nix flavors?

I can't tell you why it isn't waiting on host1, but i suppose it is simply not there (or not in the path, not flagged executable, ....). I can tell you, though, why your connection to the host is closed afterwards:

Normally, when you start a process B from another process A , A sets up B as its "child process": B will be started, executed and when it ends, its return value will be presented to A for evaluation.

With the command exec this changes: A, in fact, will start B in its own environment (the one of A) and the exit immediately so that B effectively replaces A. Because you replaces your login shell with the little script you wrote (which in turn ended) your connection was simply closed the same way it would have been if you had ended the login shell otherwise (like by pressing "CTRL-D", entering "exit", etc.).

I hope this helps.
bakunin

1 Like

Dear Friend,

Yes both are Solaris 10 servers with same OS/patch levels.

Thanks
Prem.

---------- Post updated at 08:45 PM ---------- Previous update was at 08:25 PM ----------

Hi Bakunin,

Thanks for your response. I am not worried about the connection drop.

When I hit enter to execute the command its resulting some like below.

prem@host1:exec pause 2>> /tmp/prem.log
Please Press <Enter> to continueConnection to host1 closed.

Is this something related to my input/keyboard settings?. I am expecting the program to wait for enter continue. However its reading the previous key press and exiting.

Thanks for your help.

Cheers,
Prem.

This might have something to do with your terminal settings. It is definitely NOT related to the exec command as the title suggests: the command doing the reading from the keyboard is the read .

read is a shell-builtin command and the difference in behavior might also come from different shell versions and similar differences. You might want to leave out the exec to investigate, so that you don't have to reconnect for every single attempt.

In general, though, i can't understand the reason why you are doing what you do at all. Could you please describe what you are trying to achieve - maybe there is a better/faster/more elegant way to achieve it anyways.

I hope this helps.

bakunin