Operating System - HP-UX
1827421 Members
4020 Online
109965 Solutions
New Discussion

shell-script for changing passwords

 
SOLVED
Go to solution
Deinert Arthur
New Member

shell-script for changing passwords

I have the following problem:
I must change a password for other users using a shell script which runs with system administrator rights.

My test script: (in the future, I will get the login name and the password by other way, but for testing "read login" and "read password" will be enough)

echo "login-name:"
read loginname
echo "password:"
read passw
passwd $loginname <<@
$passwd
$passwd
@

But this little here-script doesn't run!
At the end of the here-script I get twice a input line for the new password.
With other orders I already used here-scripts in similar ways without problems - how I can solve this problem?
6 REPLIES 6
Tom Geudens
Honored Contributor

Re: shell-script for changing passwords

Hi,
You can use the "expect" software for this ... and you can find that at http://hpux.tn.tudelft.nl/

Hope this helps,
Tom
A life ? Cool ! Where can I download one of those from ?
harry d brown jr
Honored Contributor

Re: shell-script for changing passwords

You need to use expect or perl.

live free or die
harry
Live Free or Die

Re: shell-script for changing passwords

This is because passwd doesn't take input from anything but a terminal (its a security feature!) - As Tom mentioned, Expect is the usual way of getting around this... If you hunt around on some expect sites, you'll probably also find a script that does exactly what you want.

HTH

Duncan

I am an HPE Employee
Accept or Kudo
harry d brown jr
Honored Contributor
Solution

Re: shell-script for changing passwords

It would be something like this:

#!/usr/local/bin/expect -f
set username $env(UNAME)
set password $env(UPASS)

spawn passwd $username
expect "New password:"
send "$password\r"
expect "Re-enter new password:"
send "$password\r"
send "exit\r"
expect eof



from:
http://www.netsys.com/sunmgr/1997-08/msg00082.html


live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: shell-script for changing passwords

And for a perl example look here (search for change_passwd.pl):

http://tlc.perlarchive.com/articles/perl/ls0001.shtml


live free or die
harry
Live Free or Die
Anonymous
Not applicable

Re: shell-script for changing passwords

From
http://aa11.cjb.net/hpux_admin/1998/0087.html
--
/usr/lbin/getprpw [-r] [-m option[,option]] logonid

NOTE. This is an undocumented command and not supported for direct use by
end users.
--
probably this already can do the job you're trying to code?