INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Find diference line and send output in the mail body

Find diference line and send output in the mail body

Find diference line and send output in the mail body

(OP)
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 --> shell

#!/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

RE: Find diference line and send output in the mail body

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.

RE: Find diference line and send output in the mail body

(OP)
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

RE: Find diference line and send output in the mail body

So if I've read this correctly and assuming the files are already sorted.

CODE --> shell

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.

RE: Find diference line and send output in the mail body

(OP)
Thank you

RE: Find diference line and send output in the mail body

(OP)
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[i]} | 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

RE: Find diference line and send output in the mail body

'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.

RE: Find diference line and send output in the mail body

(OP)
Yes, you are right

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close