Solved

alarm sound when something is put in a file

Posted on 2002-05-08
7
374 Views
Last Modified: 2010-04-21
Let us say I have a process that is running and appending some text at the end of a file so using the following command

tail -f myFile | grep alarmText        ----(1)

I will get a line of output whenever the alaramText is put on the file.

What I want is some kind of alarming sound (such as the one you get when someone initiates a "talk command" with your name), so that I will be able to know when that thing happend instead of shifting my attention and going at the xterm I am running (1).
0
Comment
Question by:oumer
  • 3
  • 3
7 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6997344
tail myFile |(grep alarmText && /bin/echo "\007")
0
 
LVL 4

Author Comment

by:oumer
ID: 6999659
first of all thanks for letting me know to use /bin/echo cause I was using just echo ,which was in /usr/bin and it doesn't work with the bell sound. but still there is some problem with the code you sent. I still get a text message but no sound. but when i tried /bin/echo "\007" the alarm sounds ok.

I wrote a small script called alarm.sh

x=0
while [ "$x" -ne 100 ]
do
/bin/echo "\007"
let x=x+1
done

which will just sound the bell 100 times and it works alone perfectly

then  I used

tail -f myFile |(grep alarmText && alarm.sh)

the output i get is the same as

tail -f myFile | grep alarmText

(I am using -f since I want to create endless check)

so I think the && ing is not working. What do you think is the problem?










0
 
LVL 4

Author Comment

by:oumer
ID: 6999665
but doing something like
echo "hi" && echo "bye" works (I mean as a standalone command without the piping and everything)
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 6999705
oops, the grep command never exits (as long as the pipe is open), so the following command does not exectute, that's the reason.

The simplest solution would be to modify your alarm.sh in that way that it gets the input, does a grep and bells. Then call it like:

   tail -f myFile |alarm.sh
0
 
LVL 84

Expert Comment

by:ozo
ID: 7000375
tail -f myFile | perl -pe 's/(alarmText)/\a$1\a/'
0
 
LVL 4

Author Comment

by:oumer
ID: 7001194
ahofmann,
i still don't get it how to return from the grep even in the alarm file, cause it seems it is constantly getting input and never returning (because of the tail piping)

and ozo,
I tried your code it doesn't work
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 7001217
#! /bin/ksh
# alarm.sh
while read line; do
    \echo "$line"|grep alarmText && /bin/echo "\007"
done
exit

then use
   tail -f myFile |alarm.sh

works for me.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now