Skip to content

Instantly share code, notes, and snippets.

@nohtyp
Last active December 31, 2015 18:49
Show Gist options
  • Save nohtyp/8029116 to your computer and use it in GitHub Desktop.
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.
#!/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