Changing an AIX password via script? Changing an AIX password via script? shell shell

Changing an AIX password via script?


You can try:

echo "USERNAME:NEWPASSWORD" | chpasswd


Use GNU passwd stdin flag.

From the man page:

   --stdin          This option is used to indicate that passwd should read the new password from standard input, which can be a pipe.

NOTE: Only for root user.

Example

$ adduser foo $ echo "NewPass" |passwd foo --stdinChanging password for user foo.passwd: all authentication tokens updated successfully.

Alternatively you can use expect, this simple code will do the trick:

#!/usr/bin/expectspawn passwd fooexpect "password:"send "Xcv15kl\r"expect "Retype new password:"send "Xcv15kl\r"interact

Results

$ ./passwd.xp spawn passwd fooChanging password for user foo.New password: Retype new password: passwd: all authentication tokens updated successfully.


In addition to the other suggestions, you can also achieve this using a HEREDOC.

In your immediate case, this might look like:

$ /usr/bin/passwd root <<EOFtesttestEOF