Counting Processes

I have a simple script that I want to notify me whenever there are anything other than one instance of a particular process running. I've always used the script:

DPID_DW=$(ps -ef | grep [d][w] | wc -l)
if [ "${DPID_DW}" -eq 0 ]
   then
        echo "The data warehouse manager for DB is down"
elif [ "${DPID_DW}" -gt 1 ]
  then
        echo "More than one instance of the DW Manager is running"
fi

,,,the problem is that the process is more than a single line. It looks like:

ps -ef | grep [d][w]
  genret 156098      1   0   Mar 19      - 167:25 /prod/jre_1.3.1/sh/java -Dprgi
d=DWManager -Xms1m -Xmx1024m -Djava.security.policy=/gers/genret/.java.policy -D
xml.catalog.files=/gers/catalog/catalog -cp /gers/genret/opt/path/gerscs.jar:/ge
rs/genret/opt/path/gersdw.jar:/gers/genret/jdbc/lib/classes12.zip:/gers/genret/m
enu/pub/sbin:/gers/genret/menu/pub/bin:/gers/genret/menu/pub/mac:/gers/genret/me
nu/adm/sbin:/gers/genret/menu/adm/bin:/gers/genret/menu/adm/mac:/gers/genret/men
u/sup/bin:/gers/genret/menu/sup/mac:/gers/genret/custom:/gers/genret/fix:/gers/g
enret/src_rev/fix:/gers/genret/opt/path:/gers/genret/bin:/g/bin:/usr/bin:/etc:/u
sr/sbin:/usr/ucb:/sbin -DVERBOSE=n com.gers.dw.DWManager

Er, you should confirm that. The output is spread across multiple lines on screen, but if you check with wc -l or grep -c, you will find that it is on a single line.

I thought the same thing, but I always get "echo "More than one instance of the DW Manager is running" message? Indicating that it is counting more than one line....

Can you actually do an echo of DPID_DW and check the value stored there?

I comes back as "2"?

x-4-1-user# dw_test
       2
x-4-1-user#