Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

line space in an empty variable

Status
Not open for further replies.

lhg1

IS-IT--Management
Mar 29, 2005
134
DK
Hi

I want to monitor the number of processes the easyest way is
Code:
ps -ef|grep <process>|grep -v grep|wc -l

But error handling would be a lot easyere if I knew the processes that where capturede - ex.
Code:
a=`ps -ef|grep <process>|grep -v grep`
number=`echo $a|wc -l`

The last one enables me to view the processes that where captures.

The problem is that last method acturly has an empty line if no processes is captures.

ex
Code:
>ps -ex|grep ThereWillNeverBeAnythingCaptured|grep -v grep|wc -l
>0

>a=`ps -ex|grep ThereWillNeverBeAnythingCaptured|grep -v grep`
>number=`echo $a|wc -l`
>echo $number
>1

I've tryede putting |awk NF but no result.

Any ideers?

Thanks
Lhg
 
Replace this:
number=`echo $a|wc -l`
with this:
[ "$a" ] && number=`echo $a|wc -l` || number=0

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top