Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
07-05-2012, 09:41 AM
|
#1
|
LQ Newbie
Registered: Jul 2012
Location: Ireland
Posts: 6
Rep:
|
How do I use "expect" to supply details after 5 line intro appears, e.g. password for
Hello,
I've a query here to do with 'expect' that I was hoping for some help with. I'd be rather new to scripting. In short I suspect I have difficulties in getting the expect to expect five lines of an intro first rather than the usual word or two like "username" or "password".
I want to configure my CentOS 5.8 so that when the machine reboots apache will start automatically. As it stands I currently must run the apache manually and then enter a password, say "blah". I had understood that I ought to be able to get apache started automatically with 'expect' and an rc.local. With that in mind I did a 'yum install expect' and created a directory called /usr/local/scripts. In here I created a file called start_httpd.sh and made it executable with a chmod 755. With apache off I did a trial run on starting apache with this file. On running the file with a ./start_httpd.sh the following appeared:
[root@]# ./start_httpd.sh
spawn /usr/local/apache2/bin/apachectl start
Apache/2.2.22 mod_ssl/2.2.22 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.
Server xxx.yyyy.com:443 (RSA)
Enter pass phrase:
and then it hung. Using a "ps -elf | grep httpd | grep -v gr" on another putty session I can see that the apache has started but is waiting for a password.
So how do I get my expect to expect:
"
Apache/2.2.22 mod_ssl/2.2.22 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.
Server xxx.yyyy.com:443 (RSA)
Enter pass phrase:
"
before sending the password?
My own script looks as follows:
#!/usr/bin/expect
#
# expect script to interactively provide the password to the apache start
# script. this runs at startup so that the apache is available automatically
# after each system boot.
#
# xxxxxx, July 2012
#
set timeout 30
# start the actual start script itself
spawn /usr/local/apache2/bin/apachectl start
# look for an indication that the Apache server is already running or not
expect {
# apache reverse proxy is running, so just exit
"httpd (pid*" {exit;}
}
# wait for the password prompt
expect {
"Apach*phrase:" {send "blah"\r";}
# "*Enter pass phrase:" {send "blah\r";}
# "*Enter pass phrase:" {send "blah\r"; exp_continue}
}
exit;
In passing if the apache is already running the script works normally in that it acknowledges httpd is running and exits fine. So the query anyhow is how do I get the expect to be able to deal with five lines before the 'Enter pass phrase:'? when the apache is not running.
Kind regards,
M
|
|
|
07-05-2012, 10:00 AM
|
#2
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
You don't need an expect script to start Apache, you can do that with the regular init system (actually this is one of its main purposes). You can use chkconfig to tell CentOS that you want to have httpd (which is Apache) started on boot: http://www.centos.org/docs/5/html/De...chkconfig.html
|
|
|
07-05-2012, 10:06 AM
|
#3
|
LQ Newbie
Registered: Jul 2012
Location: Ireland
Posts: 6
Original Poster
Rep:
|
Thanks for the comment TobiSGD. How do I supply the password then? To start the apache I enter "./apachectl start" from the /usr/local/apache2/bin/ directory and then enter a password. With chkconfig apache/httpd could be started but where would I specify the password?
|
|
|
07-05-2012, 10:08 AM
|
#4
|
Moderator
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
|
I never heard that anyone needs a password to start Apache, but I am not an expert in this matter. I would just give it a try and see if it works. If not I hope a member with more Apache experience steps in.
|
|
|
07-05-2012, 10:10 AM
|
#5
|
Senior Member
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305
Rep:
|
Quote:
Originally Posted by ms1
Thanks for the comment TobiSGD. How do I supply the password then? To start the apache I enter "./apachectl start" from the /usr/local/apache2/bin/ directory and then enter a password. With chkconfig apache/httpd could be started but where would I specify the password?
|
It is not always necessary to use expect, you can use something like this (assuming password is asked once).
Code:
./apachectl start << 'EOF'
your_password
EOF
|
|
|
07-05-2012, 10:21 AM
|
#6
|
LQ Newbie
Registered: Jul 2012
Location: Ireland
Posts: 6
Original Poster
Rep:
|
Quote:
Originally Posted by vikas027
It is not always necessary to use expect, you can use something like this (assuming password is asked once).
Code:
./apachectl start << 'EOF'
your_password
EOF
|
Thanks vikas027 but unfortunately with the above and variations of it I still have to manually enter the password after being requested for it. I feel just having the password entered automatically would be the key as I could probably go from there.
|
|
|
07-05-2012, 12:09 PM
|
#7
|
Senior Member
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144
|
Ok,
If you're posting the code use the [code] tags around the text for better reading
In your script I may see a typo, so this might be the case:
Code:
"
Apache/2.2.22 mod_ssl/2.2.22 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.
Server xxx.yyyy.com:443 (RSA)
Enter pass phrase:
"
...
# wait for the password prompt
expect {
"Apach*phrase:" {send "blah"\r";}
# "*Enter pass phrase:" {send "blah\r";}
# "*Enter pass phrase:" {send "blah\r"; exp_continue}
}
exit;
the red marked text doesn't seem the same to me, so expect probably doesn't recognize it neither.
|
|
|
07-05-2012, 12:25 PM
|
#8
|
LQ Newbie
Registered: Jul 2012
Location: Ireland
Posts: 6
Original Poster
Rep:
|
Thanks Lithos and also the tip about the [code]. I would agree that you are right that this is the location of the solution. This
Code:
"Apach*phrase:"{send "blah"\r";}
was the last variation of many I tried.
Code:
"*Enter pass phrase:" {send "blah\r";}
and
Code:
"*Enter pass phrase:" {send "blah\r"; exp_continue}
were also tried with no luck. The wildcard of * worked well with the following
Code:
expect {
# apache reverse proxy is running, so just exit
"httpd (pid*" {exit;}
}
so in principle * works. Just to get an 'expect' that matches with
Apache/2.2.22 mod_ssl/2.2.22 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.
Server xxx.yyyy.com:443 (RSA)
Enter pass phrase:
would be 90% of the way to the solution methinks.
|
|
|
07-05-2012, 01:23 PM
|
#9
|
Senior Member
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305
Rep:
|
Quote:
Originally Posted by ms1
Thanks vikas027 but unfortunately with the above and variations of it I still have to manually enter the password after being requested for it. I feel just having the password entered automatically would be the key as I could probably go from there.
|
Can you please send me a sample output of a command where you provide passwords ?
Ideally this should work, similar to below.
Code:
root@box1:~# passwd vikas << 'EOF'
> abc123
> abc123
> EOF
Changing password for user vikas.
New password: BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password: passwd: all authentication tokens updated successfully.
root@box1:~#
|
|
1 members found this post helpful.
|
07-06-2012, 06:05 AM
|
#11
|
LQ Newbie
Registered: Jul 2012
Location: Ireland
Posts: 6
Original Poster
Rep:
|
Thanks vikas027. Yes, I'll remember that as a handy way to change passwords and possibly other scipts but it doesn't seem to work here for automatically starting apache. Here is the output on restarting apache.
------------------------------------------
# ./apachectl start
Apache/2.2.22 mod_ssl/2.2.22 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.
Server huller.gosnetworks.com:443 (RSA)
Enter pass phrase:
------------------------------------------
chrism01 seems to have definite answer too (thank you) especially with the CentOS link but at the moment I'd prefer not to have to recompile the setup as someone else made the certs first day. Might have to do it though.
|
|
|
07-06-2012, 06:50 AM
|
#12
|
LQ Newbie
Registered: Jul 2012
Location: Ireland
Posts: 6
Original Poster
Rep:
|
Thanks vikas027. Yes, I'll remember that as a handy way to change passwords and possibly other scipts but it doesn't seem to work here for automatically starting apache. Here is the output on restarting apache.
------------------------------------------
# ./apachectl start
Apache/2.2.22 mod_ssl/2.2.22 (Pass Phrase Dialog)
Some of your private key files are encrypted for security reasons.
In order to read them you have to provide the pass phrases.
Server huller.gosnetworks.com:443 (RSA)
Enter pass phrase:
------------------------------------------
chrism01 seems to have definite answer too (thank you) especially with the CentOS link but at the moment I'd prefer not to have to recompile the setup as someone else made the certs first day. Might have to do it though.
|
|
|
All times are GMT -5. The time now is 08:50 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|