How to issue ctrl+D and enter key

My problem is that i have to connect Linux server. I can connect it with SSH but because of the software of the Linux server, i need to press enter and after ctrl+D. Therefore, I need to write a script that should press enter and ctrl+D. How can i write it in KSH shell script. HELP ME!

Google for the tool expect, read the howtos and try it out if it fits your needs.

What pressing the <ENTER> key prdouces is in fact a linefeed character. Therefore you can emulate it by sending such a character, which is represented by "^M" (CTRL-M).

If you are entering your program text via vi (or any other editor) you have to take measures though so that the editor doesn't enter an actual linefeed as would be the normal prceeding but will be treating the character as special character instead. In vi this is done by pressing "CTRL-V", which "escapes" the next entered character. After pressing CTRL-V in input mode you can press the ENTER key and you will see a "^M" appear (one character! you cannot separate the caret sign and the "M"). Manipulate this like any other text.

Analogously for "CTRL-D", but in this case you have an even easier means of producing it: "^D" is the EOF (end of file) character and the content of the /dev/null device is only a EOF character. The following command will put that character into the variable "eofvar" which you could manipulate like any other text:

cat /dev/null | read eofvar

Still, having said all that, zaxxon is most probably correct in pointing out expect to you. What you are likely willing to achieve is better done with it than with pure shell means.

I hope this helps.

bakunin

Firstly thanks a lot to reply my question. I will search expect but before that want to try your suggestion but the thing i did not understand how can i write the command on vi editor for ctrl+D or enter. For example when i write:
^D or "^D" ; ^M or "^M" or '^M'
these commands do nothing when execute the script. for example ^D should exit or ^M should jump another bash but they do nothing. how can i make them do smthg or how can i make the computer press enter or ctrl+D

Thanks a lot

fozay

As bakunin mentioned above, for:

^M --> press CTRL-V and the ENTER key
^D --> press CTRL-V and CTRL-D

Regards

I did what you said but when execute the script i obtain these:

./ctrl[4]: ^M: not found
./ctrl[4]: ^D: not found

thanks

it doesn't work that way. you need to use that inside the expect script - probably in a send_user call or something.

the pseudocode should look like this

spawn ssh ...
expect login { foo}
expect password { bar}
expect "login prompt or whatever" { 
   send ctrl+d
   send line feed
   interact
}

if the bash script is executing ssh, the control will not return until the ssh command completes.

It works thanks you very much. Thanks to all of you to reply me....