Computing.Net > Forums > Unix > Expect script to su and run passwd

Expect script to su and run passwd

Reply to Message Icon

Original Message
Name: jessicaD
Date: April 14, 2004 at 13:57:00 Pacific
Subject: Expect script to su and run passwd
OS: HP-UX
CPU/Ram: 750MHz 16GB
Comment:

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


Report Offensive Message For Removal








Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Expect script to su and run passwd

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software