I am trying to change a password of a user via script. I cannot use sudo as there is a feature that requires the user to change the password again if another user changes their password.
AIX is running on the system.
unfortunately, chpasswd is unavailable.
I have expected installed, but I am having trouble with that also.
here is what I thought would work
echo "oldpassword\nnewpasswd123\nnewpasswd123" | passwd user
However once run the script I am prompted with please enter user's old password
shouldn't they all be echoed in?
I am a beginner with shell scripting and this has been baffled.
In addition to the other suggestions, you can also achieve this using a HEREDOC.
In your immediate case, this might look like:
Use GNU
passwd
stdin flag.From the
man
page:NOTE: Only for root user.
Example
Alternatively you can use
expect
, this simple code will do the trick:Results
Just this
Actual output from ubuntu machine (sorry no AIX available to me):
This is from : Script to change password on linux servers over ssh
The script below will need to be saved as a file (eg
./passwdWrapper
) and made executable (chmod u+x ./passwdWrapper)
Then you can run
./passwdWrapper $user $password $server $newpassword
which will actually change the password.Note: This requires that you install
expect
on the machine from which you will be running the command. (sudo apt-get install expect
) The script works on CentOS 5/6 and Ubuntu 14.04, but if the prompts inpasswd
change, you may have to tweak theexpect
lines.You can try
LINUX
UNIX
If you dont use "-c" argument, you need to change password next time.