Problem in two scripts

I wrote one script it is showing wrong out but i wrote another script it is showing right out. I really don't know the difference.


first-script-showing mistake.

#!/bin/bash
echo "Counting the Databases"
countp1=`ps -ef |grep pmon |grep -v grep | wc -l`
echo $countp1
#countp=3
if [ $countp1 -eq 3 ]
then
echo "SUCCESSFULL"
else
echo "FAILED"
fi

#sh count-pmon-stats.sh
Counting the Databases
5
FAILED

# countp=`ps -ef |grep pmon |grep -v grep | wc -l`
echo $countp
3


small script working fine.

#!/bin/bash
countp=`ps -ef |grep pmon |grep -v grep | wc -l`
if [ $countp -eq 3 ]
then
    echo "ok"
else
    echo "nok"
fi

Hello,

Could you please post the error you are getting. So it will be a bit easy for us to figure out.

Thanks,
R. Singh

try running it as sh -x <<script name>>

Your script works fine but takes its own name count-pmon-stats.sh into account, which shows up in the process list too :wink: