Very simple script using bash language


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Very simple script using bash language
# 1  
Old 10-29-2013
Very simple script using bash language

Dear AIXians,

I have a task for very simple script, but I can't write it correctly Smilie
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:

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

# 2  
Old 10-29-2013
Hi,

Could you please try followoing code please.

Code:
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
# 3  
Old 10-29-2013
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.
# 4  
Old 10-29-2013
Hi,

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

Code:
$ 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.



Code:
1       R.Singh         110


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 10-29-2013
Thanks dear, the script id working fine now.
The final code is:

Code:
 
#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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Covert simple bash script in perl language

Hello, Anyone please covert this in perl language ######################## if ps faux | grep -v grep | grep ProcessXYZ then echo "$SERVICE is running, , everything is fine" exit 0 else echo "$SERVICE is not running" exit 2 fi Additional... (1 Reply)
Discussion started by: fed.linuxgossip
1 Replies

2. UNIX for Dummies Questions & Answers

Simple bash script menu

Dear Sir, May I know how do I go about adding the following feature into the script below: When user enter values other than 1,2,3,4, a) Message “Wrong entry !!! Pls select 1,2,3 or 4” is displayed b) The screen is cleared again and the menu is displayed. #!/bin/bash clear var=1... (2 Replies)
Discussion started by: fusetrips
2 Replies

3. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

4. Shell Programming and Scripting

Simple bash script help

Hi to everyone here, I'm a new user and relatively-new linuxer. I'm trying to write a script that checks if every file from a directory is present in a given list and if not, delete it. should be simple. But I think I've done half the work only: this is to create the reference list: for c... (2 Replies)
Discussion started by: dentex
2 Replies

5. Shell Programming and Scripting

need a simple bash script

to gather the cpu utilization from a system in 5 minute intervals and direct output to file. I'm new at scripting and while this seems like an easy task I'm confused on where to start. thanks for any help (1 Reply)
Discussion started by: mkeyes001
1 Replies

6. Shell Programming and Scripting

Help with writing simple bash script

I want to write a bash script to: 1. Send an email from localhost to an external gmail account. (gmail then automatically forwards the message back to a pop account on the same server. 2. Script waits 3 minutes then checks to see if the email arrived, and if not, it sends an email to... (9 Replies)
Discussion started by: sallyanne
9 Replies

7. Web Development

Simple Script for Multiple Language Sitemaps

Someone asked me to post a very simple script for creating multiple language sitemaps from a vbseo generated sitemap for vbulletin. You will need to create the required directories, change the paths and website name as appropriate. This code could be easily wrapped in a simple while loop and... (0 Replies)
Discussion started by: Neo
0 Replies

8. Shell Programming and Scripting

simple bash script

I am writing a shell script in bash one of the thing I want to show is size of export /home du -sk /export/home/oracle | cut -c 1-5 echo "kbytes" when I run the script kbytes shows up in the second line, How can I append kbytes on the same line, such as 61233 kbytes please guide thanks (2 Replies)
Discussion started by: Tirmazi
2 Replies

9. Shell Programming and Scripting

Simple BASH script?

Hi guys, I'm new to the forum so forgive me if I'm sounding ... daft. I currently work in a Tech Support role. Every day we have to generate data by running around 10 .sh scripts. I was thinking instead of having to ./filename 10 times is it possible to right a new script that will run these for... (16 Replies)
Discussion started by: JayC89
16 Replies

10. Shell Programming and Scripting

Simple Bash Script

I'm sure I'm doing something wrong but as I am new to bash shell scripting I'm not sure what: Here's the code webalizer.conf is sitting in the same directory as this file which is named webalizer.sh. Can someone tell me if I've got the syntax right -- it that's correct? I'm executing the... (3 Replies)
Discussion started by: xaphalanx
3 Replies
Login or Register to Ask a Question