Wednesday, August 17, 2011

Change the unix password remotely on Windows platform (cygwin)

For a user who maintains WebSphere products on many UNIX servers, it is a boring thing to change the password every 90 or 120 days.

Here is an example to change the password remotely on windows platform using cygwin

1) install cygwin using setup.exe , which can be found at the link: http://www.cygwin.com/
2) run setup.exe and make sure you select "expect" and "ssh" packages.
3) after installing cygwin, click "cygwin" on the windows desktop and you will enter cygwin interface.
4) create an expect shell script  like following:


         #!/usr/bin/expect

         set hostname unixhost1
         set user user1
         set password oldpassword
         set newpass newpassword

         spawn ssh -l $user $hostname

         expect "assword:"
         send "$password\r"

          expect "#"
          send "passwd\r"
          expect "Old password:"
          send "$password\r"
          expect "New password:"
          send "$newpass\r"
          expect "gain:"
          send "$newpass\r"
          expect "#"
          send "exit\r"

4) run the script and you can change the user password on the host you specified in the script.



No comments:

Post a Comment