I need the improvement for my script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I need the improvement for my script
# 1  
Old 06-02-2014
I need the improvement for my script

Hi All,

Here is my script
Code:
#! /bin/sh
var1=some email id
var2=some email id
grep -i "FAILED FILE FORMAT VALIDATION" /opt >tmp2
diff tmp1 tmp2 | grep ">" >tmp3
if [ $? -eq 0 ]
then
   cat tmp3 | mailx -s " Error Monitoring" $var2
else
   echo "Pattern NOt Found" | mailx -s " Error Monitoring" $var1
fi
cat tmp2 >>tmp1
rm tmp3
rm tmp2

When executing this script for one time i am getting the right output and for the secind time also i am getting the right output.When i ran it for the third time im not getting the right output.
Could anyone guide me in generating the right script.
Whenever i search a pattern,and if the pattern was found then var2 must execute and when not found var1 must execute.If the same pattern found again it doesn't mail me that pattern.It must mail me pattern not found.

Last edited by vbe; 06-02-2014 at 05:01 PM.. Reason: code tags + indent
# 2  
Old 06-02-2014
There are several problems here...

Is this a homework assignment? If it is, please fill out the complete homework template and refile your request in the Homework & Coursework Questions forum.

If not, what type of file is /opt? (The grep utility isn't intended to work on directories.) If it is a regular file, what is in it?

What does the program email do on your system when given the operand id? How does the value of the variables var1 and var2 in the environment affect its behavior?

What is in the file tmp1 when you run your script each of the first three times?

What is the "right output" for each of the 1st three times when you run this script?

What operating system are you using?

What diagnostics did your script produce each of the 1st three times you ran it?
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Performance improvement in grep

Below script is used to search numeric data from around 400 files in a folder. I have 300 such folders. Need help in performance improvement in the script. Below Script searches 20 such folders ( 300 files in each folder) simultaneously. This increases cpu utilization upto 90% What changes... (3 Replies)
Discussion started by: vegasluxor
3 Replies

2. UNIX for Dummies Questions & Answers

Improvement in shell script

Hi This is my Following code: #!/bin/sh echo "TOTAL_NO_OF_MAILS" read TOTAL_NO_OF_MAILS echo "TOTAL_NO_OF_TICKETS " read TOTAL_NO_OF_TICKETS echo "TICKETS_IN_QUEUE" read TICKETS_IN_QUEUE rm -rf `pwd`/Focus echo "Hi Team\nSTATS IN CLRS MAIL BOX\n\n==============================" >> Focus... (11 Replies)
Discussion started by: wasim999
11 Replies

3. UNIX for Advanced & Expert Users

linux os improvement

can anyone help to share the knowledge on linux os improvement? 1) os account - use window AD authentication, such as ldap, but how to set /etc/passwd, where to put user home? 2) user account activity - how to log os user activity share the idea and what tools can do that...thx (5 Replies)
Discussion started by: goodbid
5 Replies

4. Shell Programming and Scripting

Looking for improvement to script that compresses a directory that is 2 months old

I write reports daily to a directory that is named with the month and year. I wanted to compress all but the last two months worth of these directories to save space. I am going to cron a job to run on the first of each month to do this clean up. I didn't have zip/unzip on my AIX environment so... (0 Replies)
Discussion started by: slatoms
0 Replies

5. Shell Programming and Scripting

Any improvement possible in this script

Hi! Thank you for the help yesterday This is the finished product There is one more thing I would like to do to it but I’m not to certain On how to proceed I would like to log all output to a log in order to Be able to roll back This script is meant to be used in repairing a... (4 Replies)
Discussion started by: Ex-Capsa
4 Replies

6. Shell Programming and Scripting

Script ready but might need some improvement.

Hi All, I have written a script which does some editing in the files, based on user input.This might not be the most elegant way of doing it and there would be many improvements needed. Please go through it and let me know how it could be improved. Suggestions are welcome!! Thanks!... (2 Replies)
Discussion started by: nua7
2 Replies

7. Programming

File - reading - Performance improvement

Hi All I am reading a huge file of size 2GB atleast. I am reading each line and cutting certain columns and writing it to another file. Here is the logic. int main() { string u_line; string Char_List; string u_file; int line_pos; string temp_form_u_file; ... (10 Replies)
Discussion started by: dhanamurthy
10 Replies
Login or Register to Ask a Question