Skip to content

Instantly share code, notes, and snippets.

@hypnguyen1209
Created December 18, 2021 13:55
Show Gist options
  • Save hypnguyen1209/d9d69c7efb875f0068aad2a021916c24 to your computer and use it in GitHub Desktop.
Save hypnguyen1209/d9d69c7efb875f0068aad2a021916c24 to your computer and use it in GitHub Desktop.
#!/bin/bash
touch old.txt new.txt mail.txt
who > new.txt
while read -r line
do
check=$(grep -w "$line" -m 1 old.txt)
if [[ ! $check ]]
then
echo "User" "$(echo "$line" | awk '{print $1}')" "dang nhap thanh cong vao thoi gian" "$(echo "$line" | awk '{print $4}')" "$(echo "$line" | awk '{print $3}')" >> mail.txt
fi
done < new.txt
cat new.txt > old.txt
sendmail root@localhost < mail.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment