Skip to content

Instantly share code, notes, and snippets.

@alloydwhitlock
Created March 13, 2014 20:10
Show Gist options
  • Save alloydwhitlock/9535961 to your computer and use it in GitHub Desktop.
Save alloydwhitlock/9535961 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Name: sudoaudit
# Author: Adam Whitlock
# Version: 0.1
# Purpose: Send e-mail when sudo is invoked by a user
#
# Note: Please setup the following parameters in /etc/sudoers:
# mailto: "[email protected]
# mail_always: on
#
# Don't forget to alias sudo to this script!
auditemailaddress=“[email protected]"
hostname="${HOSTNAME}"
if [ "${1}" == "" ]; then
/usr/bin/sudo -h
exit 1
fi
echo -e "Please provide the reason why sudo needs to be used or type 'quit' to return: "
read answer
if [ "${answer}" = "quit" ]; then
echo -e "\nExiting 'sudo'...\n\n"
else
echo "${answer}" | mail -s "${hostname}" ${auditemailaddress}
/usr/bin/sudo ${@}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment