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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Expect script to su and run passwd

Reply to Message Icon

Name: jessicaD
Date: April 14, 2004 at 13:57:00 Pacific
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



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Expect script to su and run passwd

Creating Script to Shutdown/Startup www.computing.net/answers/unix/creating-script-to-shutdownstartup/7848.html

how to unzip and find a file? www.computing.net/answers/unix/how-to-unzip-and-find-a-file/8343.html

script to send email if su executed www.computing.net/answers/unix/script-to-send-email-if-su-executed/5525.html