So far with:
#!/bin/bash
tail -fn0 /var/log/dirsrv/redacted-domain/audit | \
while read line ; do
echo "$line" | grep -C 5 -i "add: member"
if [ $? = 0 ]
then
mail -s "New User Added" me@email.com > /dev/null
fi
echo "$line" | grep -C 5 -i "add: nsaccountlock"
if [ $? = 0 ]
then
mail -s "Account Disabled" me@email.com > /dev/null
fi
done
I want to take the contents of grep matches from the file /var/log/dirsrv/redacted-domain/audit
and throw them into an e-mail to me@email.com
. It feels redundant (and does not work regardless) to throw the grep statement into the email itself with the above loop.
Sorry, I should include a sample of what is being grepped:
time: 20200114133315
dn: cn=users,cn=groups,cn=accounts,dc=ipa,dc=domain,dc=com
result: 0
changetype: modify
add: member
member: uid=example_user,cn=users,cn=accounts,dc=ipa,dc=domain,dc=com
I want to find a match of type add: member
and return the entire ^ into an email.