Solved

Script does not set the variable and does not execute

Posted on 2014-01-08
4
421 Views
Last Modified: 2014-01-09
Hi experts.

This script is in aix 5.3.
The variable Param9 is not being set and then the script does not execute.

#!/bin/ksh
PATH=/home/app/oracle/product/10.2.0/bin:/home/app/oracle/product/10.2.0:/usr/ccs/bin:/usr/bin/X11:/usr/lib:/usr/bin:/etc:/usr/sbin:/usr/ucb:/sbin:/usr/local/bin:/home/app/oracle/product/10.2.0/OPatch
export PATH
PARAM9=! ps -ef| grep -v grep | grep bpbkar|wc -l
if [[ $PARAM9  -gt 0 ]] ; then
  kill -9 $(ps -ef | grep -v grep | grep bpbkar | awk '{print $2}')
fi
0
Comment
Question by:LindaC
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
Comment Utility
Hi again,

the correct assignment is:

PARAM9=$(ps -ef| grep -v grep | grep bpbkar|wc -l)

You could as well run just the kill statement unconditionally:

 kill -9 $(ps -ef | grep -v grep | grep bpbkar | awk '{print $2}') 2>/dev/null

"kill" against an empty string will do no harm, of course, and since we're discarding the resulting error message nothing will be displayed on the terminal.

Another alternative:

PID=$(ps -ef | grep -v grep | grep bpbkar | awk '{print $2}')
[[ ! -z $PID ]] && kill -9 $PID

A bit shorter (the old regex trick):

PID=$(ps -ef | grep bpbka[r] | awk '{print $2}')
[[ ! -z $PID ]] && kill -9 $PID
0
 
LVL 8

Author Comment

by:LindaC
Comment Utility
I have executed the statements, but  the only statement that gave me a result with the echo now is the assignment to the PARAM9 variable:

psprdbsvr:/home/oracle/dba/scripts/PRD> PARAM9=$(ps -ef| grep -v grep | grep bpbkar|wc -l)
psprdbsvr:/home/oracle/dba/scripts/PRD> echo $PARAM9
0


psprdbsvr:/home/oracle/dba/scripts/PRD> PID=$(ps -ef | grep -v grep | grep bpbkar | awk '{print $2}')
You have mail in /usr/spool/mail/oracle
psprdbsvr:/home/oracle/dba/scripts/PRD> echo $PID

psprdbsvr:/home/oracle/dba/scripts/PRD> PID=$(ps -ef | grep bpbka[r] | awk '{print $2}')
psprdbsvr:/home/oracle/dba/scripts/PRD> echo $PID

psprdbsvr:/home/oracle/dba/scripts/PRD>
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
Comment Utility
So, where's the problem?!
PARAM9=0 with wc -l says means "not found", so the 2nd command (PID) won't display anything (unless found)...
0
 
LVL 8

Author Comment

by:LindaC
Comment Utility
Oh! ok, I though that if didin't find nothing it was supposed to show 0, but I don't know unix. So thank you as always.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now