LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-15-2011, 12:40 PM   #1
bret
Member
 
Registered: Apr 2005
Location: SLC, Utah
Distribution: RHEL 4, RHEL 5
Posts: 59

Rep: Reputation: 16
Automatically passing an answer to a command's prompt


I am running a command that wants a response. I would like to do this through a shell script to automatically reply to the prompt. Here is the command I am running:

[root@server1]# service kdump propagate
Using existing keys...
kdump@server2's password:

So, how can I get a script to call the above routine, and then pass it the password, without being prompted at the terminal. I've tried piping the password, but this does not work:

[root@server1]# echo Mypassword | service kdump propagate
Using existing keys...
kdump@server2's password:

I get the same response. Any ideas?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 12-15-2011, 02:38 PM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,419

Rep: Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532
Quote:
Originally Posted by bret View Post
I am running a command that wants a response. I would like to do this through a shell script to automatically reply to the prompt. Here is the command I am running:

[root@server1]# service kdump propagate
Using existing keys...
kdump@server2's password:

So, how can I get a script to call the above routine, and then pass it the password, without being prompted at the terminal. I've tried piping the password, but this does not work:

[root@server1]# echo Mypassword | service kdump propagate
Using existing keys...
kdump@server2's password:

I get the same response. Any ideas?
Yes...check into using "expect" in your script:
http://www.unix.com/shell-programmin...-examples.html
http://linux.die.net/man/1/expect
 
2 members found this post helpful.
Old 12-16-2011, 08:07 AM   #3
bret
Member
 
Registered: Apr 2005
Location: SLC, Utah
Distribution: RHEL 4, RHEL 5
Posts: 59

Original Poster
Rep: Reputation: 16
Thumbs up

That was it! Thanks so much TBOne. I wrote a small "expect" routine to answer the prompts: Here's what I did:

#!/usr/bin/expect -r
# set variables
set password MyPassword
spawn service kdump propagate
# Look for password prompt
expect "password:"
# Send password aka $password
send -- "$password\r"
expect eof
 
1 members found this post helpful.
Old 12-16-2011, 09:01 AM   #4
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,419

Rep: Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532Reputation: 2532
Glad it worked for you, and thanks for following up, so others can benefit too.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capturing Print Screen from command Prompt and Saving automatically to Clipboard kiratjohal Linux - Screenshots 1 09-07-2011 07:00 PM
passing parameters from a unix shell prompt into a windows cmd.exe prompt nano2 Programming 1 09-01-2009 11:26 AM
GUI automatically answer tools on linux billzhu123 Linux - Enterprise 2 05-05-2005 06:44 AM
Passing params to Lilo with out a prompt ? michael_util Linux - General 1 02-11-2005 02:19 PM
prompt for root password and passing to a program ludeKing Programming 4 08-23-2004 08:55 PM


All times are GMT -5. The time now is 01:03 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration