You are not logged in.
I'm trying to do this:
tail -f /var/logfile | grep -C 0 text | mail -s "OUTPUT OF GREP" mail@mail.com
How can I do this?
Offline
maybe with a variable
tail -f /var/logfile | grepout=$(grep -C 0 test) | mail -s "$grepout" mail@mail.com
// nope, doesn't work
Last edited by demian (2011-05-20 15:17:19)
no place like /home
github
Offline
Haven't tested it but try
mail -s $(tail -f /var/logfile | grep -C 0 text) mail@mail.com
Edit: Are you sure it will work with 'tail -f'?
Seems that the subject can't contain certain characters:
[karol@black ~]$ mail -s $(tail /var/log/kernel.log | grep -C 0 detected) foo@bar.com
18:05:11 contains invalid character ':'
kernel: contains invalid character ':'
[ contains invalid character '['
8.433910] contains invalid character ']'
4-0:1.0: contains invalid character ':'
^C
How will you escape multiple newlines?
Last edited by karol (2011-05-20 15:20:07)
Offline
I think tail -f will always intefere. You'd have to use normal tail and instead create a loop to check it every ~ secs or so.
no place like /home
github
Offline
How about putting the output inside the e-mail?
echo "$(tail /var/log/kernel.log | grep -C 0 swap)" | mail -s somesubject foo@bar.com
This works nicely.
Offline
It's important that the output goes to the subject.
To simplify , How would you do this?
cat file | grep word | command -x grepoutput
Offline
Did you try what I posted? It does exactly that.
Offline
falconindy: you replied fast I had to reload the page to see your comment
I'm testing your commnad, I still dont fully understand it. But for the little I tested it's not working.
I executed it, waited a bit for many new lines to be added to the log file. Only after I finish the command with CONTROL+C, one mail is send with only 1 of the log lines added to the subject.
Offline
Offline
Thanks falconindy. It works now, you really are a Bash Ninja.
Offline
Please mark as solved...
Offline