Solved

Script does not set the variable and does not execute

Posted on 2014-01-08
4
437 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 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 13

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

752 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