Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Script does not set the variable and does not execute

Posted on 2014-01-08
4
Medium Priority
?
444 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 2000 total points
ID: 39766227
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
ID: 39767672
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 14

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 39767715
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
ID: 39767839
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

927 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