Requirement: Alert if there is any package installed or removed in the ubuntu server.
For this requirement, I'm trying to use inotifywait to continuously monitor dpkg.log, if there are any changes using regex pattern for installed and removed package and alert based on that.
How can I take the modified content of a file which is being monitored by inotifywait to another file or store it in a variable, so that I can apply some regex and alert based on that?
Please help me how can I do this, or Is there any other way that I can achieve this requirement using any other tool.
This is what I was trying but this is not working.
#!/bin/sh
while inotifywait -e modify /var/log/dpkg.log; do
if tail -n1 /var/log/dpkg.log | grep installed; then
// alert script
fi
done