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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple send Script 1

Status
Not open for further replies.

tekpr00

IS-IT--Management
Jan 22, 2008
186
CA
Hell All,

I am flabbergasted by Korn Shell's behavior.
I wrote a simple script as follows:
chk_sp_cop.sh:
Code:
csp=`ps -ef | grep -v grep | grep sp_cop | wc -l`

if test $csp -ne 4
then
  mailx -s "SharePlex Configuration Processes(SPCP)" me@aol.com<<EOM
One or more SharePlex Configuration Processes are down on SERVER.
Please refer to the document - SharePlex Configuration Monitoring and Error Fixes.
Section:chk_sp_cop on how to fix this issue.
EOM
fi

However, it still sends email, even when evaluation operation :
oracle::..ome/app/oracle-> ps -ef | grep -v grep | grep sp_cop | wc -l
4
oracle::..ome/app/oracle->
Please note I wrote a smilar script on the same server that is working perfectly.
Script Name: chk_eventmon.sh
Code:
c=`ps -ef | grep -v grep | grep sp_eventmon | wc -l`
#
if test $c -ne 2
then
mailx.........
..........
..........
I mainly copied from chk_eventmon.sh to chk_sp_cop.sh and modified the later.
I scheduled both on crontab:
55 * * * * /orahome/app/oracle/admin/scripts/chk_eventmon.sh
55 * * * * /orahome/app/oracle/admin/scripts/chk_sp_cop.sh

This is on Sunos BTW.

Again, chk_eventmon.sh is working as it should be, but chk_sp_cop.sh is not.
 
Hi

tekpr00 said:
I mainly copied from chk_eventmon.sh to chk_sp_cop.sh and modified the later.
I would say, you mainly copied its content, but changed its naming scheme :
Code:
csp=`ps -ef | grep -v grep | grep [green]sp_cop[/green] | wc -l`
[gray]# also matches script name :  chk_[/gray][green]sp_cop[/green][gray].sh[/gray]
Code:
c=`ps -ef | grep -v grep | grep [red]sp[/red][green]_eventmon[/green] | wc -l`
[gray]# not matches script name :    c[/gray][red]hk[/red][green]_eventmon[/green][gray].sh[/gray]
So when your chk_sp_cop.sh is running, there is one more process who's name is matched by [tt]grep sp_cop[/tt] : the script itself.

Feherke.
feherke.ga
 
Thanks, for pointing this out....
I changed the name of the script from chk_sp_cop.sh to chk_spcop.sh, and all is fine after that.
Again, thanks.
 
Hello feherke:

Thanks for helping out the other time.
However, I will like to improve on the script.

Currently, my code chk_envemotn is as follow:
Code:
csp=`ps -ef | grep -v grep | grep sp_sp_eventmon | wc -l`

if test $csp -ne 12
then
  mailx -s "SharePlex Configuration Processes(SPCP)" me@aol.com<<EOM
One or more SharePlex Configuration Processes are down on SERVER.
Please refer to the document - SharePlex Configuration Monitoring and Error Fixes.
Section:chk_sp_cop on how to fix this issue.
EOM
fi

In addition to counting the number of lines as above, I will like it to identify missing instance and suggest ways to restart it.
The output of the line - ps -ef | grep -v grep | grep sp_sp_eventmon:
oracle/11.2.0.4 - ctxa)/orahome/app/SharePlex/11g/prod/bin> ps -ef | grep -v grep | grep sp_eventmon
oracle 23696 1 0 Feb 27 ? 1:54 /bin/ksh /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -[highlight #EF2929]u2350_etx[/highlight]
oracle 4604 1 0 Feb 27 ? 1:53 /bin/ksh /orahome/app/SharePlex/10g/prod/.app-modules/sp_eventmon -s -u2150_sfg
oracle 27614 1 0 Feb 27 ? 1:58 /bin/ksh /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -u2100_ctx
oracle 14185 1 0 Mar 01 ? 1:01 /bin/ksh /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -u2500_ctx
oracle 666 1 0 Feb 27 ? 1:57 /bin/ksh /orahome/app/SharePlex/10g/prod/.app-modules/sp_eventmon -s -u2100_sfg
oracle 27499 1 0 Feb 27 ? 1:55 /bin/ksh /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -u2150_ctx
oracle 6368 1 0 Feb 27 ? 1:55 /bin/ksh /orahome/app/SharePlex/10g/prod/.app-modules/sp_eventmon -s -u2250_sfg
oracle 15824 1 0 Feb 27 ? 1:57 /bin/ksh /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -u2250_ctx
oracle 6307 1 0 Feb 27 ? 2:23 /bin/ksh /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -u2200_ctx
oracle 21974 1 0 Feb 27 ? 1:55 /bin/ksh /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -u2300_etx
oracle 22738 1 0 Feb 27 ? 1:52 /bin/ksh /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -u2450_etx
oracle 26662 21995 0 08:59:23 pts/7 0:07 /bin/ksh /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -u2400_etx

First, this command: ps -ef | grep -v grep | grep sp_sp_eventmon has a glitch of missing the last character in the output. Maybe because I am using SunOS, not sure.
THe Output should be like:
oracle 23696 1 0 Feb 27 ? 1:54 /bin/ksh /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -u[highlight #CC0000]2350_etxe[/highlight]
But sorry for digressing.

I will like to modify script abouve to compare a field in the ouput records ([highlight #CC0000]u2350_etxe[/highlight]) to my exisiting active_instance_field.txt file, and send email advising the recipient to restart the mising instance.

Content of my active_instance_field.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

Here is attempt:
Code:
csp=`ps -ef | grep -v grep | grep sp_sp_eventmon | wc -l`

if test $csp -ne 12
then
  mailx -s "SharePlex Configuration Processes(SPCP)" me@aol.com<<EOM
One or more SharePlex Configuration Processes are down on SERVER.
cspa=`ps -ef | grep -v grep | grep sp_sp_eventmon` > current_active_inst.txt
#extract field 2350_etxe from line /orahome/app/SharePlex/11g/prod/.app-modules/sp_eventmon -s -u2350_etxe[indent][/indent][indent][/indent][indent][/indent][indent][/indent][indent][/indent]
[indent]for active_inst in `cat current_active_inst.txt|\Efrep ‘sp_eventmon -s -u2150_sfge’ | grep –v \*|cut –fi –d’ sp_eventmon -s -u’`[/indent]
[indent]compare variable active_inst to each record in the file active_instance_field.txt[/indent]
[indent]if not present[/indent]
[indent]Please evaluate the reason for the cracsh of $active_inst and restart with the follwoing example[/indent]
[indent]nohup ./sp_eventmon -s '-u2350_etxse' -t 30 -p /orahome/app/SharePlex/11g/var2350_etxe -m /dev/null &[/indent]
EOM
fi
 
Hi

Not really sure what exactly you tried to put in the last code, but personally I would start with something like this :
Code:
ps -C sp_eventmon hocmd [teal]|[/teal] [gray]# list processes with command name sp_eventmon, do not display list header, display only cmd column[/gray]
sed [i][green]'s/.*-u//'[/green][/i] [teal]|[/teal] [gray]# keep only the part after -u[/gray]
grep -v -f - active_instance_field[teal].[/teal]txt [teal]|[/teal] [gray]# from that file output those not listed by ps[/gray]
sed [i][green]'s!.*!nohup ./sp_eventmon -s -u& -t 30 -p /orahome/app/SharePlex/11g/var& -m /dev/null [/green][/i][lime]\&[/lime][i][green]!'[/green][/i] [gray]# format the list as shell commands[/gray]

See whether your [tt]ps[/tt] accepts any of those options. Also check whether it accepts column width specifier like [tt]ps -C sp_eventmon hocmd[highlight]:256[/highlight][/tt]. I think the truncating things comes from [tt]ps[/tt]'s formatting. If nothing helps, maybe you could reverse the options to have that -u 1[sup]st[/sup] to not get it truncated.


Feherke.
feherke.ga
 
this thread might help for actual mailx commands.
thread822-1764492


==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top