Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find diference line and send output in the mail body

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
CA
Hello I have two files as follow:

man_exist_instances.txt
2100_ctxd
2100_sfgd
2200_sfga
2200_ctxa
2150_sfgi
2150_ctxi
2250_sfgm
2500_ctxd

AND

sys_exist_instances.txt
2650_sfg
2250_sfg
sfga_220
2700_etx
2250_ctx
2650_etx
2100_sfg
2200_ctx
2150_sfg

The objective is to compare man_exist_instances.txt to sys_exist_instances.txt, and generate:
result_instances.txt
2400_etx
2450_etx
2600_etx
2650_etx
sfga_220
sfga_220

The next thing is to take each line in result_instances.txt, obtain full name from man_exist_instances.txt to produce final file_mail.txt.

Last request is to attach the file file_mail.txt to an email and send it to usera.

Here is my attempt

Code:
#!/bin/ksh
#
# Script Name:  chk_eventmon.sh
#
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------

`ps -ef | grep -v grep | grep sp_eventmon | cut -c123-130 > sys_exist_instances.txt`
#
`diff <(cut -c1-8 sys_exist_instances.txt| sort) <(sort man_exist_instances.txt| cut -c1-8) | grep "<" | cut -c3- > result_instances.txt`
i=0
patterns=`cat result_instances.txt`
values=[cat man_exist_instances.txt]
for pattern in ${patterns}
do
  cat -n ${values[i]} | grep $pattern >> file_mail.txt
  ((i++))
done
        mailx -s "SP Configuration Processes(SPCP)" usera@a.com<<EOM

        Please evaluate the reason for the cracsh and restart echo "$(cat \$file_mail.txt)" monitoring using the follwoing example:

        nohup ./sp_eventmon -s '-u2200_sfga' -t 30 -p var2200_sfga -m /dev/null &
EOM

Howevern when I execute above, I am getting:
./chk_eventmon_new.sh[25]: man_exist_instances.txt]:

However I do have man_exist_instances.txt
-rwxrwxr-x 1 oracle dba 180 Mar 30 16:45 man_exist_instances.txt
-rw-r--r-- 1 oracle dba 0 Mar 31 11:01 file_mail.txt
-rwxr-x--- 1 oracle dba 1337 Mar 31 11:58 chk_eventmon_new.sh
-rw-r--r-- 1 oracle dba 180 Mar 31 12:09 sys_exist_instances.txt
-rw-r--r-- 1 oracle dba 54 Mar 31 12:09 result_instances.txt

Please help
 
Ermm maybe I'm being thick here, but you seem to have some "results" that are not in either set.


So could you elaborate on:
"The objective is to compare man_exist_instances.txt to sys_exist_instances.txt, and generate: result_instances.txt"

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Thanks Chris for your observation.

The list of each set was not complete, I posted a subset of each for abbreviation. Here is the complete sets.

man_exist_instances.txt
2100_ctxd
2100_sfgd
2200_sfga
2200_ctxa
2150_sfgi
2150_ctxi
2250_sfgm
2500_ctxd
2250_ctxs
2500_etxd
2550_ctxa
2550_etxa
2600_ctxd
2600_sfgd
2500_etxi
2650_sfgi
2700_etxs
2700_sfgi

sys_exist_instances.txt
2650_sfg
2250_sfg
sfga_220
2700_etx
2250_ctx
2650_etx
2100_sfg
2200_ctx
2150_sfg
2600_etx
2550_ctx
2400_etx
2600_sfg
2100_ctx
2150_ctx
2450_etx
sfga_220
2500_ctx
2700_sfg
2200_sfg

result_instances.txt
2400_etx
2450_etx
2600_etx
2650_etx
sfga_220
sfga_220
 
So if I've read this correctly and assuming the files are already sorted.

Code:
comm -12 man_exist_instances.txt sys_exist_instances.txt > result_instances.txt && mutt -s [subject here]  < result_instances.txt someone@somewhere.tld

Not actually tested but it looks ok.

{comm -12} will output lines that are in both files, and mail or mailx could be used if 'mutt' isn't installed.



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Hello Chris, I dont want to output lines in both files.
Here is the situation. I have 2 files sys_exist_instances.txt:
2250_sfg
2250_ctx
2650_etx
2100_sfg
2200_ctx
2150_sfg
2600_etx
2550_ctx
2400_etx
2600_sfg
2100_ctx
2150_ctx
2450_etx
2500_ctx
2200_sfg
2700_etx

The second file is man_exist_instances.txt:
2150_ctxi
2250_ctxs
2100_sfgd
2250_sfgm
2300_etxd
2350_etxs
2400_etxa
2100_ctxd
2200_ctxa
2150_sfgi
2450_etxi
2200_sfga
2450_etxi
2450_etxi
2550_ctxa
2600_sfgd
2650_etxi
2650_sfgi
2700_etxs
2700_sfgm

When I compare both files the difference gave me result_instances.txt:
2500_ctx
2600_etx

Now I want 9 digit field instead of my current result 8 digit field. So I do another compare of result_instances.txt and man_exist_instances.txt to extract corresponding 9 digit field in man_exist_instances.txt while sending email:
i=0
patterns=`cat result_instances.txt`
while values=cat man_exist_instances.txt
for pattern in ${patterns}
do
cat -n ${values} | grep $pattern >> file_mail.txt
((i++))

done
mailx -s "Configuration Processes(SPCP)" user@sand.com<<EOM

Please evaluate the reason for the cracsh and restart echo "$(cat \$file_mail.txt)" monitoring using the follwoing example:

nohup ./sp_eventmon -s '-u2200_sfga' -t 30 -p /orahome/app/SharePlex/10g/var2200_sfga -m /dev/null &
EOM

However, this is erroring out.
Please help

 
'comm' can be used to output any combination of the input file lines, the -1|2|3 options suppress the 'matches' that are not required.

So a quick recap;

Two files containing values, one with 8 char lines and one with 9 char lines.

After a comparison of the 8 char line data (file one) to the first 8 characters of the 9 char file data (file two), you want to email the 9 character data line to someone@somewhere.tld

Sound about right?



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top