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



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-09-2009
Registered User
 

Join Date: Aug 2009
Posts: 1
feeding interactive shell commands

Hi,
like if i want to authenticate and i 100% know the password and username

i can run a script with
su - username
and then feed in the password through file pass.txt

script.sh < pass.txt

but if i don't know in which order the script is going to prompt for the input is there a way i can selectively answer prompts in a script mentioning the input before in a file like

if script asks for user:
input xyz
and if script ask password first
123456

please recommend
regards
Ltoso
Sponsored Links
  #2 (permalink)  
Old 08-09-2009
scottn's Avatar
scottn scottn is offline Forum Staff  
Moderator
 

Join Date: Jun 2009
Location: Zürich, CH
Posts: 1,858
Hi.

I don't know if it's that easy when you don't know the exact order of input your scripts expects.

But there is a tool - called expect - that may be able to help you.

Although I've never used it, I've seen it mentioned here a few times, and it does seem interesting.

expect(1) - Linux man page

Simple Telnet Automation Using Expect
(this isn't the exact example you were looking for, but it's not far off, I think)
  #3 (permalink)  
Old 08-09-2009
Registered User
 

Join Date: Jul 2008
Location: Texas
Posts: 140
I'm not sure I understand. I've never seen su prompt for user name. Or is the example of the script prompting for user name unrelated to su?

Anyway, one way to be able to selectively respond to requests for input is to use Expect.
  #4 (permalink)  
Old 08-09-2009
Registered User
 

Join Date: Nov 2006
Posts: 326
For unix shell script I don't think so it's possible to input passwords, unless you are doing automated ftp from a script or sql scripts is possible unix level for normal shell scripts I think not possible.

Quote:
example
ftp -inv 192.168.1.1 << EOF
user oracle pass apple$2 (syntax varies)
asc
hash
cd /etc
<do something>
EOF
However If you could su from root and run su command, then just

Quote:
example: su - oracle -c /home/oracle/bin/dbstart <<---(don't need to specify any passwords)
best of luck
  #5 (permalink)  
Old 08-09-2009
TonyFullerMalv's Avatar
Registered User
 

Join Date: Sep 2008
Location: Malvern, Worcs. U.K.
Posts: 984
You can use and expect(1) script for this.

Here is an example where the order of the quesions is known:

Code:
#!/usr/local/bin/expect 
spawn telnet <machine ip> 
expect "login:" 
send "<username>\n" 
expect "Password:" 
send "<password>\n" 
send "bash\n" 
send "cd /opt\n" 
send "ls -ltr\n"  (if you are not giving \n then it will wait for your response or u have to type enter manually). 
interact      

How to execute the “expect“ command  expect –f <file name> 
Ex: expect –f <filename>.expect

from:
http://en.kioskea.net/forum/affich-37067-shell-script-to-telnet-and-run-commands#p96218

Expect can also respond to a list of questions with the appropriate answer using a while loop, e.g. (script to supply answers to fsck):

Code:
while 1 {
	expect {
		eof			{break}
		"UNREF FILE*CLEAR\\?"	{send "y\r"}
		"BAD INODE*FIX\\?"	{send "n\r"}
		"\\? "			{interact +}
		}
	}

# The last question mark is a catch all.
#  \\ prevents the next character from being interpreted as a wild card.


Last edited by TonyFullerMalv; 08-09-2009 at 11:34 AM..
Sponsored Links
Closed Thread

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to make interactive shell script a automated one? bhaskar_m Shell Programming and Scripting 2 02-03-2009 01:51 AM
Can BASH execute commands on a remote server when the commands are embedded in shell bash_in_my_head Shell Programming and Scripting 1 12-04-2008 01:51 AM
Schedule an interactive shell script Chaitrali Shell Programming and Scripting 4 11-08-2007 11:49 AM
Korn shell interactive script leonard905 Shell Programming and Scripting 3 08-02-2007 03:16 PM
need help in implementing simple interactive shell in C nix1209 Programming 2 03-15-2006 09:26 AM



All times are GMT -4. The time now is 08:51 AM.


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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0