views:

84

answers:

3

Hi Everyone,

I have a bash shell script that requires ctrl-D to break out of the terminal.can anyone tell me how to use it in the shell script

example

ssh host last --->displays the list of users who were logged on to that host

i have different hosts the output is appended to one final and when i'm executing this particular shell script along with other series of commands, i'm using ctrl-D to see the output

suppose my shell script is myscript.sh to execute myscript.sh

./myscript.sh

ctl-D

connection to host closed

output is displayed

instead i want to use ctrl-D in my script file

Any ideas on this are appreciated.

Thanks,

A: 

There is no way to do this directly. Use a heredoc to feed stdin instead.

./someprog.sh << EOF
something here
EOF
Ignacio Vazquez-Abrams
@Abrams thanks, but i tried executing the above cmd i'm getting this ? EOF Pseudo-terminal will not be allocated because stdin is not a terminal. > can you tell me wats happening thanks
Shruti
Then tell ssh to do so.
Ignacio Vazquez-Abrams
A: 
#! /bin/sh
echo 'Enter one line at a time'
echo 'Press CTRL+D to finish'
cat >test.out
echo 'OK'
spraff
This works because `cat` is a separate process, the CTRL-D hits that instead of your script, kills it, and returns control.
spraff
A: 

Why don't you tell last how many lines you want to see? Then you won't have to interrupt it with a Ctrl+D. For example, to see 10 lines use:

ssh hostname "last -10"
dogbane