Score:0

Script to notify me when users are created

aw flag

I've created a script from what ive found on the web to notify a SA of users being added to a server. I have it setup with a cron to run the script every 5 mins to monitor differences in the /var/log/secure file but it still sends a blank email if nothing has changed. How can i edit it to not email if no changes are made. Script is below:

file="/var/log/secure"

while cmp "$file" "${file}_bkp"; do
  sleep 2
done
diff "$file" "${file}_bkp" | grep -e useradd | mailx -s "User Added On Server" [email protected]
cp "$file" "${file}_bkp"
in flag
Zabbix just stores a checksum of /etc/passwd. If a user is added the file and therefore the checksum changes.
Score:0
bw flag
dgj

I agree with the comment that a more performant method of checking is to monitor the /etc/passwd file instead of analyzing a log file, that could potentially be a large, intensive file to process. If the /etc/passwd is detected to have changed, you could diff a backup of the file to see what has changed.

Quick example that you could customize to your exact needs.

# One-off initial Set up
md5 -q /etc/passwd > /etc/passwd.md5
cp /etc/passwd /etc/passwd.compare
# Cron job script logic
if [[ $(md5 -q /etc/passwd) != $(< /etc/passwd.md5) ]]
then
  # The passwd file has changed, do something!
  # 
  # Diff /etc/passwd with /etc/passwd.compare to get details, etc.
  # Send an alert with details
  # 
  # Prepare for the next time a change happens.
  md5 -q /etc/passwd > /etc/passwd.md5
  cp -f /etc/passwd /etc/passwd.compare
  #
fi

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.