Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello -
I'm trying to write an expect script to first su to another user adn then run the passwd command. I created it by using autoexpect and then modified it to take command line parameters. The problem I'm having is that each part works by its self, but when I try to run the passwd after I run the su portion, it just hangs until I kill the session.Any suggestions??
Thanks!!
Jessica
#!/patch/expect-5.40/expect -f
#
# This Expect script was generated by autoexpect on Mon Apr 12 15:55:56 2004
# Expect and autoexpect were both written by Don Libes, NIST.
#set force_conservative 1 ;# 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 username [lindex $argv 0]
set oldpass [lindex $argv 1]
set pass [lindex $argv 2]set timeout -1
spawn $env(SHELL)
match_max 100000
expect -exact "\$ "
send -- "su - $username\r"
expect -exact "su - $username\r
Password: "
send -- "$oldpass\r"
expect "\r
pstserv1:/psoft/$username\$ "
sleep 1
send -- "passwd\r"
expect -exact "passwd\r
Changing password for $username\r
Old password: "
send -- "$oldpass\r"
expect -exact "\r
New password:"
send -- "$pass\r"
expect -exact "\r
Re-enter your new password: "
send -- "$pass\r"
expect -exact "\r
pstserv1:/psoft/$username\$ "
send -- "exit\r"
logout\r
\$ "
expect eof

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |