Skip to main content
Question

How to use Casper Variables in expect Script


L3nny5
Forum|alt.badge.img+8

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!

3 replies

davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • 1811 replies
  • August 25, 2015

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
    }
}

davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • 1811 replies
  • August 27, 2015

Hi,

Did that work in the end?


L3nny5
Forum|alt.badge.img+8
  • Author
  • Contributor
  • 20 replies
  • August 28, 2015

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
    }
}

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings