Very simple script using bash language

Dear AIXians,

I have a task for very simple script, but I can't write it correctly :confused:
I have a file called (out.txt), if any line of this file starts with the word 'ORA', it must send email, if the file (out.txt) don't have this word, so it do nothing.

Please tell me how.

Anyway, I wrote this bad script:

checking=`cat /home/out.txt | grep -i ORA-`
if [ $checking ]
then
      mail -s "Found ORA word in the file" -r anymail@anything.com
fi

Hi,

Could you please try followoing code please.

if [[ -z $checking ]]
then rest of your code please
 

Note: this condition tells if there is an empty value for checking then send mail as per your code.

Thanks,
R. Singh

Great, thanks RavinderSingh13

But how can I force (grep tool) to search in beginning of the lines. Because I don't need to search in all the file, just in each beginning of each line.

Hi,

Just an example for same, let us say we need to search the lines starting with 1.

$ cat test_own
1       R.Singh         110
2       R.Singh         100
3       R.Singh         90
4       R.Singh         140
5       rinku             80
6       rinku             90

$ cat test_own | grep '^1'

Output will be as follows. It will show only lines which are being started by 1 so you can take referance from here.

1       R.Singh         110

Thanks,
R. Singh

Thanks dear, the script id working fine now.
The final code is:

 
#This script is looking for the word ORA- in the alert log file, then send MAIL.
#!/bin/sh
if grep -iFq "^ORA-" /home/out.txt
then
    mail -s "Found ORA word in the file" -r anymail@anything.com
else
    mail -s "no ORA word in the file" -r anymail@anything.com
fi