Filtering/Finding a "Fortune" message

Hi,

I have had a problem in Linux with the "Fortune" messages (unfortunately! :frowning: ) and I need to trap the message again. It starts with a "IMPORTANT NOTICE".

To capture this, I write a script as follows..

#!/bin/sh
a=0
while [$a -lt 1000] ; do
/usr/games/fortune >> fortune.txt
a=`expr $a + 1`
done

Now, the file is so big and I haven't been recapture the message yet. So I want to do the following. If the output from the command '/usr/games/fortune' contains the string "IMPORTANT", then I want to store it or else dont. Any suggestions?

Thanks,
OldTrash

The fortune program prints a random line from some file (/usr/games/lib/fortunes or something like that). So just grep your message from that file.

I don't know anything about fortune or why you are running it 1000 times, but you want to use grep to "filter out" the message:

/usr/games/fortune | grep 'IMPORTANT' >> fortune.txt

I too am unsure of the purpose of this thread :eek:

Aaaaaanyway...

$ cd /usr/share/fortune
$ grep "IMPORTANT" fortunes
$ grep "IMPORTANT" fortunes2
**** IMPORTANT ****  ALL USERS PLEASE NOTE ****

Due to a recent systems overload error your recent disk files have been
erased.  Therefore, in accordance with the UNIX Basic Manual, University of
Washington Geophysics Manual, and Bylaw 9(c), Section XII of the Revised
Federal Communications Act, you are being granted Temporary Disk Space,
valid for three months from this date, subject to the restrictions set forth
in Appendix II of the Federal Communications Handbook (18th edition) as well
as the references mentioned herein.  You may apply for more disk space at any
time.  Disk usage in or above the eighth percentile will secure the removal
of all restrictions and you will immediately receive your permanent disk
space.  Disk usage in the sixth or seventh percentile will not effect the
validity of your temporary disk space, though its expiration date may be
extended for a period of up to three months.  A score in the fifth percentile
or below will result in the withdrawal of your Temporary Disk space.

Is that really what you want?! :rolleyes:

Cheers
ZB

:slight_smile: That's cool.. Out of the box solution..
Thanks to all replied..