Last active
December 31, 2015 18:49
-
-
Save nohtyp/8029116 to your computer and use it in GitHub Desktop.
This script will change the password on the local server and send an email if it failed or completed the job.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MYHOST=`hostname -s` | |
MYPW='!QAZXSw2@' | |
MYUSER='root' | |
NEWPASS="$MYHOST$MYPW" | |
MYEMAIL='<email list>' | |
echo -e "$NEWPASS\n$NEWPASS" | (passwd --stdin $MYUSER) | |
if [ "$?" = 0 ]; then | |
echo "Password was changed for $MYUSER on `hostname`!" > /root/.mychange | |
mail -s "Password change script ran on `hostname`" < /root/.mychange $MYEMAIL | |
else | |
echo "Password change failed for $MYUSER on `hostname`!" > /root/.mychange | |
mail -s "Your $MYUSER password change failed on `hostname`! Please investigate." < /root/.mychange $MYEMAIL | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment