I have a problem with reading the last line of file in Linux Ubuntu. I have a file named auth.log and I'm trying to read it last line after new line was added (after file was modified).
I know i need to use tail -1 /var/log/auth.log
to get last line but I don't know how to check the file every time it was modified.
After reading the last line i need to check if it contains "login" word and if yes I need to send this line by email. As far as I know grep needs to be use with mail command.
Any help would be awesome, thanks!
Maybe something like this would work for you, using tail -f
to continuously monitor the file:
while read -r; do
echo "$REPLY" | mail your@email.address
done < <(tail -f /var/log/auth.log | grep --line-buffered login)
But this would be running continuously in the background, rather than as a cron job or something.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.