|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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 |
|
|
|
||||
|
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) |
|
|||
|
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. |
|
|||
|
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:
Quote:
|
|
||||
|
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 |
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
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 |