Hi,
Something like this should work. This probably isn't the best written shell script you're ever gonna see but I just knocked it out and it works for me
Read the comments in the code to see what each part is doing.
Code:
#! /bin/bash
#
# script to automate password reset
#
# declare variables
declare USERNAME="TEST" # This allows the username to be changed or multiple usernames specified by creating a new variable
declare TMP_VAR="" # Temporary variable we will use to store value of user check
#
echo "Start password reset script"
# first check to make sure user exists
TMP_VAR=`grep ^$USERNAME: /etc/passwd` > /dev/null > 2>&1
if [ "$TMP_VAR" = "" ];
then {
echo "User $USERNAME does not exist"
# exit cleanly with result code 1 (not successful)
exit 1;
}
else {
# if username exists proceed to reset password
passwd --stdin $USERNAME < pass_file # pass_file is the file where the password is stored you want to use
}
fi
# exit cleanly and return 0 result code
exit 0;
Since you say you want to "automate" this change I'm thinking it's going to be done on a regular basis so my opinion is to add it to the crontab for root, or someone who has privileges to change user passwords. I don't know how much you know about crontabs and their purpose and so on but you can just search the forum/google and you should see plenty of examples. If you wanted to schedule the job to run at midnight on the first of every month your entry into the crontab might look like this:
Code:
0 0 1 * * /full/path/of/script/password_change.sh