Understanding 'ongoing monitoring'


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Understanding 'ongoing monitoring'
# 1  
Old 05-09-2011
Understanding 'ongoing monitoring'

Hello - very newbie here.

I have a file that I want to monitor.
Whenever a certain word is added to the end I want to be notified.

I have figured out how to do it manually... ie:

Code:
tail /path/to/file/TransferLog.txt | grep Total

When I type this in - I get no output if the word 'Total' is not yet there - and I see the line printed out when it is found.
So far so good.

What I'd like to do is set this 'watching' in motion - have it check every 5 minutes or so until the word 'Total' shows up - then, stop checking and shoot me an email - or other desktop notification (that part I have figured out) - it's the starting and repeating the check that I am unsure how to do.

I am running this on /bin/bash
Thanks for any advice (or keywords to search)


Jeff
# 2  
Old 05-09-2011
Code:
tail -f yourfile

# 3  
Old 05-09-2011
OK - didn't realize I could use -f in this way!

I'm trying now to trigger an event when grep finds this line...

Code:
#! /bin/bash
if [ tail -f -n 2 /Volumes/Cache-A/TransferLog.txt | grep Total ] ; then
do more stuff
fi

However - it gives me an error saying that :
Code:
line 2: [: missing `]'

Am I allowed to use -f in this way? Or is there something else that I can do to trigger something when it sees the 'Total' in the file?

Thanks,
Jeff
# 4  
Old 05-10-2011
Some parts of the following script are a bit sketchy but the logic should be clear:

Code:
#! /bin/bash

pAction()
{
      mail -s "Subject goes here" you@youraddress.com <<-EOT
     Some text
     This is the found line: \"$1\"
     This is some command output: $(date)

     EOT
     return $? 
}



# main()

typeset    chLine=""
typeset    fWatch="/Volumes/Cache-A/TransferLog.txt"

tail -f -n 2 $fWatch | grep "Total" |\
while read chLine ; do
      pAction "$chLine"
done

exit 0

I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

Understanding & Monitoring CPU performance (Load vs SAR)

Hi all, Been reading a lot of the cpu load and its "analogy of it to car traffic path of expressway" From wiki Most UNIX systems count only processes in the running (on CPU) or runnable (waiting for CPU) states. However, Linux also includes processes in uninterruptible sleep states... (13 Replies)
Discussion started by: javanoob
13 Replies

2. Shell Programming and Scripting

Need your help in understanding this

Hi, I found this in a script and I would like to know how this works Code is here: # var1=PART1_PART2 # var2=${var1##*_} # echo $var2 PART2 I'm wondering how ##* makes the Shell to understand to pick up the last value from the given. (2 Replies)
Discussion started by: sathyaonnuix
2 Replies

3. Shell Programming and Scripting

Insert ongoing numeration in each line?

Hi. I have a text file with lines like this: ( chp_testfile_0065 "Blablabla." ) ( chp_testfile_0003 "Blablabla" ) ( chp_testfile_0123 "Blablabla" ) I need one more 0 in each line, so that I have 5 digits in a sequence. I also need an ongoing numeration from 1 to n, so that (... (12 Replies)
Discussion started by: Bloomy
12 Replies

4. AIX

Help in Understanding ISMP

Hi, Good day to everyone. This is my first time joining the community and wanted to say thanks in advance for all your help and assistance. First, I am not expert in AIX and UNIX but I do know a thing or two and I have a simple question regarding ISMP. We are using AIX 5.3 and a couple... (0 Replies)
Discussion started by: lgalang
0 Replies

5. UNIX for Dummies Questions & Answers

Understanding Groups

Hi cat /etc/group : .... oinstall:x:401: dba:x:400:oracle ... cat /etc/passwd|grep oracle oracle:x:130:401::/home/oracle:/bin/ksh 1. Is that mean that : ORACLE user has OINSTALL as it Primary group and DBA as secondary group ? 2. What is the linux comman to set ORACLE user with... (2 Replies)
Discussion started by: yoavbe
2 Replies

6. UNIX for Dummies Questions & Answers

understanding {%/*}/

Hi Gurus: I am trying to understand the following line of code.I did enough of googling to understand but no luck.Please help me understand the follow chunk of code: X=$0 MOD=${X%/*}/env.ksh X is the current script from which I am trying to execute. Say if X=test.ksh $MOD is echoing :... (3 Replies)
Discussion started by: vemana
3 Replies

7. Shell Programming and Scripting

Help in understanding the following commands

Hi , Please help me in understanding the below commands temp="$dirname.temp.cc.$$" This will eliminate any trailing white spaces??? k=$(grep -cvE " |\+|-|0|1|\f" $temp if (substr(file,2,24) ~ /{13,}/) {print "N" file} -- this is inside an awk script (4 Replies)
Discussion started by: justchill
4 Replies

8. Shell Programming and Scripting

need help understanding mv

I just started shell coding and I'm a bit confused on how 'mv' works can someone explain to me how it works and if i did this correctly. Thanks. echo "Enter Name of the first file:" read file1 #echo $file1 if ; then echo "Sorry, file does not exist." exit 1 ... (16 Replies)
Discussion started by: taiL
16 Replies
Login or Register to Ask a Question