How to issue ctrl+D and enter key


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to issue ctrl+D and enter key
# 1  
Old 07-09-2009
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!
# 2  
Old 07-09-2009
Google for the tool expect, read the howtos and try it out if it fits your needs.
# 3  
Old 07-09-2009
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:

Code:
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
# 4  
Old 07-09-2009
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
# 5  
Old 07-09-2009
As bakunin mentioned above, for:

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

Regards
# 6  
Old 07-09-2009
I did what you said but when ı execute the script i obtain these:

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

thanks
# 7  
Old 07-09-2009
Quote:
Originally Posted by fozay
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

Code:
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simulate enter key

I have a popup window that appears on every boot up. I would like to have it dismissed automatically each time instead of having to hit the enter key. I thought I could write a script that would execute on startup. I tried this xdotool key return andy@7_~/Downloads$ xdotool key ... (7 Replies)
Discussion started by: drew77
7 Replies

2. Shell Programming and Scripting

Expect command to send the user input enter or ctrl+c

Hey All, I am writing one script using expect, that script which is used in spawn will accepts only 1. Enter 2. Ctrl+c Press Control-C to exit, Enter to proceed. Could some one share some thoughts to send the above user inputs in linux expect block ? Thanks, Sam (0 Replies)
Discussion started by: SCHITIMA
0 Replies

3. UNIX for Dummies Questions & Answers

Ctrl-enter doesn't work when running Midnight Commander in xterm

When running MC in xterm or gnome-terminal, it doesn't seem to allow the use of Ctrl-enter and Ctr-shift-enter to copy marked files to the command line. Does anyone know of another way to cause this to happen or a way to enable it under xterm/gnome-term? With thanks, Narnie (0 Replies)
Discussion started by: Narnie
0 Replies

4. Shell Programming and Scripting

enter key solaris

Hi, When I run script on Sun Solaris (sassetup), it prompts to "Press Enter To Continue". Now I want to automate this, ie put sassetup in a script file. So, when I run this file, it should be executed automatically without waiting for anyone to press Enter Key. I have tried the following... (1 Reply)
Discussion started by: sajjunaqvi
1 Replies

5. Shell Programming and Scripting

How to delete ctrl key values in a given string?

Hi all, My query is... in the runtime, you are getting any input string. Unfortunately, you have pressed some ctrl keys or esc keys or arrow keys while typing input string. You can get the input value like that... input string as welcome^ So ,I want to remove those unwanted keys... (4 Replies)
Discussion started by: balan_mca
4 Replies

6. Shell Programming and Scripting

How to find entering ENTER key?.

Hello All, i have a script to get input from the user like bellow, read -p "Do you want to continue (y/n) : " status i want to identify the pressing of Enter Key with out giving any value for the above statement and i want get the status if we press Enter key during run time. How to... (0 Replies)
Discussion started by: tsaravanan
0 Replies

7. UNIX for Advanced & Expert Users

using enter key in shell script

without pressing the enter key ..manually... how can we read the enter key ..from the shell script..so that the script termintes automatically. eg: telnet a.b.c.d xxxx now " how to read the enter key" tho terminate the script (1 Reply)
Discussion started by: bishweshwar
1 Replies

8. UNIX for Dummies Questions & Answers

Pressing backspace key simulates enter key

Hi, Whenever i press the backspace key, a new line appears, i.e. it works like a enter key. :confused: Thanks (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies

9. Shell Programming and Scripting

read the ENTER key

Hi , I do the following : ]echo "Do you want to say yes or no ?(y/n):\c" read ans here 'n' is the default value.that means if the user press ENTER key then it should be 'n' . Now how do i know that the user has pressed ENTER key.What will be stored in my variable 'ans'. (4 Replies)
Discussion started by: sars
4 Replies

10. Shell Programming and Scripting

Disabling ctrl-Z key inside shell script

Hi I have tried to disable the CTRL-Z key inside a shell(sh) script using the command trap "`echo "Ctrl-Z key disabled"`" 20But I am not able to exit from the script after pressing CTRL-Z key. How to proceed this? Need reply soon (11 Replies)
Discussion started by: suganthic
11 Replies
Login or Register to Ask a Question