Solved

Script does not set the variable and does not execute

Posted on 2014-01-08
4
440 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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 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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

632 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