frum
1
Hi all,
Below is a script I'm writing and giving me error:
#!/usr/bin/sh
if [ ps -ef|grep dw.sap|wc -l -gt 17 ]; then
echo "Success!"
else
echo "Failure!"
fi
Normally if I do
ps -ef|grep dw.sap|wc -l
it gives me output of 18. So my script checks if it's greater than 17 it echoes success else failure
Please suggest how to correct this.
regards.
Hello,
Could you please try the following and let us know.
if [[ `ps -ef|grep dw.sap|wc -l` -gt 17 ]]; then
echo "Success!"
else
echo "Failure!"
fi
Thanks,
R. Singh
1 Like
frum
3
Hi Ravinder,
Thanks. It works fine now.
regards.
vbe
4
#!/usr/bin/sh
if [ $(ps -ef|grep dw.sap|wc -l) -gt 17 ]; then
echo "Success!"
else
echo "Failure!"
fi
Use -c
with grep
instead of wc -l
#!/usr/bin/sh
if [ $( ps -ef | grep -c dw.sap ) -gt 17 ]; then
echo "Success!"
else
echo "Failure!"
fi
The following are more precise perhaps (you didn't provide a ps output)
$( ps -ef | grep -c 'dw[.]sap' )
$( ps -ef | grep -wc 'dw[.]sap' )
1 Like