1833378 Members
3151 Online
110052 Solutions
New Discussion

expect giving problem

 
prasad_15
Advisor

expect giving problem

Anybody can send me a expect script for logging into the system.
this following script is failing

set username testuser
set oldpasswd tesyy344
set newpasswd 1Xe7tfyz
set timeout_org $timeout
set timeout 3

set prompt "(%|#|\\\$) "

spawn rlogin -l $username localhost

expect "assword: " {
send "$oldpasswd\r"
} timeout {
set timeout $timeout_org
send_user "Time Out\n"
exit
}

Any suggestions !
6 REPLIES 6
curt larson_1
Honored Contributor

Re: expect giving problem

Expect inclues a number of examples. The README file in the example directory contains a complete list as well as full explanations about each of the examples. The example called "passmass" logs into another system and changes the password. You can probably modify this for your requirements.

The README file in the distribution also describes the locaton of the Expect archive which holds even more scripts.

http://expect.nist.gov/FAQ.html
is the url for the expect FAQ

http://expect.nist.gov
is the url for the expect home page.

the home page includes links to the examples that are included with expect.
John Meissner
Esteemed Contributor

Re: expect giving problem

Here is a script I've used many times... it works perfectly.. you need to edit you username and password.

All paths lead to destiny
curt larson_1
Honored Contributor

Re: expect giving problem

#!/depot/path/expect --
# xrlogin - rlogin but with current DISPLAY
#
# You can extend this idea to save any arbitrary information across rlogin
# Don Libes - Oct 17, 1991.

if {[llength $argv] != 1} {
puts "usage: xrlogin remotehost"
exit
}

set prompt "(%|#|\\$) $" ;# default prompt
catch {set prompt $env(EXPECT_PROMPT)}

set timeout -1
eval spawn rlogin $argv
expect eof exit -re $prompt
if {[string match "unix:0.0" $env(DISPLAY)]} {
set env(DISPLAY) "[exec hostname].[exec domainname]:0.0\r"
}
send "setenv DISPLAY $env(DISPLAY)\r"
interact

John Meissner
Esteemed Contributor

Re: expect giving problem

just a note... the script i attached was made using autoexpect from my linux box. autoexpect comes with expect....

type:

autoexpect -f telnet servername

then commense to logging in and doing your thing. when you hit ^d (control d) it writes to . you will then need to do some editing of the file and remove the datestamp and a few other lines... use my script attached in my earlier message as an example.
All paths lead to destiny
curt larson_1
Honored Contributor

Re: expect giving problem

#!../expect --
# telnet-cwd - telnet but with same directory
#
# You can extend this idea to save any arbitrary information across telnet
# Don Libes - Oct 17, 1991.

set prompt "(%|#|\\$) $" ;# default prompt
catch {set prompt $env(EXPECT_PROMPT)}

eval spawn telnet $argv
interact -o -nobuffer -re $prompt return
send "cd [pwd]\r"
interact

prasad_15
Advisor

Re: expect giving problem


Hi All,

Finally what I was able to do is as below.
It takes both cases
1- when the password expires
2- whenever you need changing the password

Any suggestions to improve this.



#!/usr/local/bin/expect -f
#

#USAGE big_exp.exp [host] [username] [oldpw] [newpw]

set host [lindex $argv 0]
set username [lindex $argv 1]
set oldpw [lindex $argv 2]
set newpw [lindex $argv 3]

set pw_stat 0 ;# set to 1 for expired passwords

log_file /tmp/JUNK

set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}

set timeout -1

spawn rlogin $host -l $username
match_max 100000

expect {

-exact "Password: " {
send "$oldpw\r"

send "$newpw\r"
send "passwd $username\n"
expect "password:"
send "$oldpw\r"
expect "password:"
send "$newpw\r"
expect "password:"
send "$newpw\r"
}
-re "expired" {
send "$oldpw\r"
send "$newpw\r"
send "$newpw\r"
}
}


send "exit\n"
send "exit\n"
expect eof

Thank You All.