The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Ctrl-M at end of each line navi Shell Programming and Scripting 3 06-04-2008 03:09 AM
Catching ctrl-C or ctrl-D sendhilmani123 Shell Programming and Scripting 2 05-02-2006 05:02 PM
how to enable Ctrl + C in ksh dradhzn Shell Programming and Scripting 0 05-01-2006 10:32 PM
Disable ctrl-c,ctrl-d,ctrl-d in ksh script wtofu AIX 6 06-29-2005 04:41 PM
Script ctrl+c newtounix UNIX for Dummies Questions & Answers 1 03-19-2001 05:23 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-09-2009
fozay fozay is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 13
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 (permalink)  
Old 07-09-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,277
Google for the tool expect, read the howtos and try it out if it fits your needs.
  #3 (permalink)  
Old 07-09-2009
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
  
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,628
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 (permalink)  
Old 07-09-2009
fozay fozay is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 13
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 (permalink)  
Old 07-09-2009
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,305
As bakunin mentioned above, for:

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

Regards
  #6 (permalink)  
Old 07-09-2009
fozay fozay is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 13
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 (permalink)  
Old 07-09-2009
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
  
 

Join Date: Dec 2007
Posts: 427
Quote:
Originally Posted by fozay View Post
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.
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0