Posted on 08-25-2015 08:12 AM
Hello,
I have an expect script which I copied from user "ktappe" and I want to integrate the $4-$11 variables so I don't have to change the script every time I need to change the password.
This example doesn't work. :-(
#!/usr/bin/expect -f
set newpassword $5
set oldpassword $6
spawn firmwarepasswd -setpasswd
expect {
"Enter password:" {
send "$oldpassword
"
exp_continue
}
"Enter new password:" {
send "$newpassword
"
exp_continue
}
"Re-enter new password:" {
send "$newpassword
"
exp_continue
}
}
Thanks!
Posted on 08-25-2015 10:51 AM
Try [lindex $argv 5]
and [lindex $argv 6]
#!/usr/bin/expect -f
set new password [lindex $argv 5]
set oldpassword [lindex $argv 6]
spawn firmwarepasswd -setpasswd
expect {
"Enter password:" {
send "$oldpassword
"
exp_continue
}
"Enter new password:" {
send "$newpassword
"
exp_continue
}
"Re-enter new password:" {
send "$newpassword
"
exp_continue
}
}
Posted on 08-27-2015 09:33 AM
Hi,
Did that work in the end?
Posted on 08-28-2015 01:43 AM
Sorry. Haven't had the time yet to test it until now.
Unfortunately it does not work. But i figured it out myself!
The number of the variable you are using needs to be minus 1. So if you are using variable 4 and 5, you have to use [lindex $argv 3] and [lindex $argv 4]
The Script for variable 4 and 5 looks like this and is working:
#!/usr/bin/expect -f
set newpassword [lindex $argv 3]
set oldpassword [lindex $argv 4]
spawn firmwarepasswd -setpasswd
expect {
"Enter password:" {
send "$oldpassword
"
exp_continue
}
"Enter new password:" {
send "$newpassword
"
exp_continue
}
"Re-enter new password:" {
send "$newpassword
"
exp_continue
}
}