Recently I’ve been having issues with a VirtualBox machine crashing at random. The only common thread is a line of log file, and so far, google has not been helpful in determining the root cause. This machine is important enough that I need to know when it crashes, but not important enough to actually take the time to fix properly, so I researched and created a command to toss into cron to check the log file for the error line and email me when it finds it.
1 |
grep '<search text>' <file path> | ifne mailx -s "<email subject>" user@example.tld -E |
The command itself is simple. Search the log file with grep, if the search generated results send an email. I tried several iterations of this before finding one that did not email when the search was empty and also did not generate silent errors when empty as well. I run this via cron at 5 minute intervals
To use this command on ubuntu 14.04 you will need to install mailutils and moreutils
Software and versions used or mentioned:
mailutils
mailx
moreutils
ifne
Resources:
Forum post with grep | mailx solution
ServerFault post with ifne solution
You must log in to post a comment.