Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a bash or perl script that change password ???

Status
Not open for further replies.

trong

Programmer
Aug 1, 2001
11
VN

Anyone know a bash or perl script that change password for a specified user ?

With best regard !!!

Trong
 
passwd <username> would seem to fit the bill. Or do you have something else in mind?
 
Expect is very good for this kind of thing..
If it is not installed(usually not), then it is under the tcl dir in your distro or got to to get the newest and greatest.

#!/usr/bin/expect
set timeout -1

proc password { pass } {
global name timeout
log_user 0
spawn -noecho passwd $name
expect {
-gl &quot;New*&quot;
sleep 1s
send &quot;$pass\r&quot;
expect {
-gl &quot;*Pass*&quot; {
sleep 1s
send &quot;$pass\r&quot;
}
}
}

while 1 {
puts &quot;Quit to quit.&quot;
send_user &quot;Name of user: &quot;
expect_user -re &quot;(.*)\n&quot; {
set name $expect_out(1,string)
if {[regexp &quot;(Q|q)uit&quot; $name]} {
exit
}
}
send_user &quot;$name password: &quot;
expect_user -re &quot;(.*)\n&quot; {
set pass $expect_out(1,string)
}

password $pass
}

There are good scripts at the expect site (nist), and
the basic idea here is that the proc expect patterns to match are tunable by you....
Use the command exp_internal 1 in this script to debug it,
for your version of passwd. Sometimes the patterns do not match and expect keeps on looking, so you need to watch the debugger to see what is happening.

Good Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top