LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-24-2005, 06:13 AM   #1
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Rep: Reputation: 18
[Expect scripting] send problem


Hello,
In order to automate a script to create a new user and set his password, I'm trying to learn the expect scripting.

I have the following testscripts:

*****************************************
#!/bin/bash
# exptest3.bash
# produce some output, reques user input.

char="abcdefgh"
echo "are you ready?(y/n)"
read resp
if [ resp == "y" ] <<<<<<<<<< what a stupid fool I be.... [ "$resp" == "y" ]
then
echo "$char"
read resp2
else
echo "quitting jah"
read resp2
exit 1
fi
exit 0
*****************************************
*****************************************
#!/usr/bin/expect -f
# exptest3
# work with the bash script.

set timeout 5
spawn /home/lieven/testscripts/exptest3.bash
expect "are you ready?(y/n)\r" {send -- "y\r"}
expect "abc*\r"
send_user "what will be first\n"
send -- "bullshit\r"
*****************************************

However, I never seem to be able to send a plain "y" which the bash script expects for the first part of the if block.

And I cannot change the send -- "y\r" to send -- "y" because then the expect script will not continue and will just timeout.

Anybody who sees what I'm (obviously) missing here?
How can I send just the one character? I also tried with send -- "y\n" but problem remains. And when I remove the "--" so it's not send as a string, then I still have the problem that the script times out because the exptest3.bash's read statement expects a newline or return if I'm not mistaking. However, I have the impression that the bash script's read statement ignores the newline when running the script "manually" (without exp script that is.)

thanks already,

Lieven

Last edited by ldp; 01-24-2005 at 10:00 AM.
 
Old 01-24-2005, 02:39 PM   #2
ldp
Member
 
Registered: Apr 2004
Location: Belgium Antwerpen
Distribution: slackware - knoppix
Posts: 141

Original Poster
Rep: Reputation: 18
Ok, now I still have some problems with the following code:

<code>
#!/usr/bin/expect -f

exp_version -exit 5.41.0

set usr [lindex $argv 0]
set pwd [lindex $argv 1]

send_user "$usr, $pwd\n"

set timeout 5
spawn -noecho passwd $usr
match_max 100000
expect "*New password:\r"
send -- "$pwd\r"
expect {
"Re-enter*password:\r" send -- "$pwd\r"
"*New password:\r" send -- "$pwd\r"
}
expect "*changed\r"
send_user -- "\r"
</code>

It seems to me that the send here always waits till $timeout seconds before sending the string
And in this case, script times out without changing the password.
If I don't assume that the password is always strong (so passwd wouldn't tell me that I gave a bad password) then it works fine like:

<code>
...
expect "*New password:\r"
send -- "$pwd\r"
expect "Re-enter*password:\r"
send -- "$pwd\r"
...
</code>

Even in the latter case, the script waits $timeout seconds before continuing. But at the end, the password is changed succesfully.

thanks for any hints.

Lieven
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI script problem: Send/Expect command echo on webpage rajatgarg Programming 2 07-11-2004 04:38 PM
Automae telnet log in and execute commands (expect and send) rajatgarg Linux - Networking 0 06-24-2004 11:37 AM
expect scripting Deltron3030 Linux - Newbie 2 12-16-2003 01:56 PM
problems with scripting in expect wedgeworth Linux - Software 1 10-07-2003 03:34 PM
expect scripting syntax problems...(catch, echo,....) wedgeworth Linux - Software 2 10-02-2003 09:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:31 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration