LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   can output of tail be redirected? (https://www.linuxquestions.org/questions/linux-newbie-8/can-output-of-tail-be-redirected-438231/)

linuxdawg 06-10-2006 06:34 AM

Emailing output of tail -f
 
How would I be able to do something like this:

tail -f log | grep "I'm finished" | mail -s "It Is Finished" me@mine.com

What I want is as soon as tail -f detects the string "I'm finished", to email me@mine.com the output of the "grepped" string (not the entire log) and return me to a command-prompt.

Is that doable?

dsids 06-12-2006 01:28 AM

check out this thread
http://www.linuxquestions.org/questi...d.php?t=438231

spirit receiver 06-12-2006 04:46 AM

You could use process substitution:
Code:

#! /bin/bash

while read
do
        mail -s "New line in logfile" dude <<- EOF
        Hi Dude,
        a new line was appended to your logfile. Here it is:
        $REPLY
        EOF
done < <( tail -f logfile )

Note that this will spawn an extra process for the tail command, which will still be running if the script itself is finished.

oily_rags 10-14-2006 04:07 PM

hi i'm trying to do a tail of the processes under my system. I can't seem to get it to work. I have tried doing tail this way

tail -f|ps aux

The processes display but it is static it's not updating the processes. I'm doing this just to understand the tail and Pipe commands, I might want to try redirecting the output to a text file too just for fun. Any thoughts guys? Thanks

timmeke 10-16-2006 02:19 AM

Quote:

i'm trying to do a tail of the processes under my system.
What do you mean by this? Do you want to run tail on the output of some of your processes? Or do you want
tail to filter the output of your "ps" command, that gives you a list of processes?

Assuming you mean the latter:
ps -aux just lists some running processes once, not continuously, so you don't need tail's -f option.
Also, I think you have the order of the commands reversed:
Code:

ps -aux | tail
displays only the last few lines of ps's output. You can control how many lines you want by adding "-n" (replace n with the number you want) to "tail".

And finally, try to start a new thread when you have a question, rather than hijacking someone else's, which is against the forum policy.


All times are GMT -5. The time now is 01:57 AM.