Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Script does not set the variable and does not execute

Posted on 2014-01-08
4
Medium Priority
?
442 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
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…
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.
Suggested Courses

688 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