Operating System - HP-UX
1827809 Members
2154 Online
109969 Solutions
New Discussion

Re: Getting "argument expected" error while running the script

 
SOLVED
Go to solution
RamkumarA
Respected Contributor

Getting "argument expected" errow while running the script

Hi Experts,

 

Below is my script to check the agent daemon health and its failing with "argument expected" error as given below.

shcscp18:/clocal/cschpov/user/t1982ra $ cat /tmp/test.sh
for server in `cat /tmp/test.txt`
do
echo "Checking the agent health on $server"
if [ `sudo /opt/OV/bin/OpC/opcragt $server | egrep 'ovbbccb|ovconfd|coda|opcmsga|opcacta|opcmsgi|opcle|opcmona' | awk '{print $(NF-1)}' | grep "isn't" | uniq` = "isn't" ]
then
echo "$server has some of the agents in not running state" >> /tmp/problematic_servers.txt
else
echo "$server is ok"
fi
done
shcscp18:/clocal/cschpov/user/t1982ra $ sudo /tmp/test.sh
Checking the agent health on odxgdd01.oddc.chrysler.com
/tmp/test.sh: test: argument expected

shcscp18:/clocal/cschpov/user/t1982ra $ cat /tmp/test.txt
odxgdd01.oddc.chrysler.com
odxgqa05.oddc.chrysler.com
odi005nimp01.oddc.chrysler.com
avibvp1osv.bvap.chrysler.com 

shcscp18:/clocal/cschpov/user/t1982ra $ sudo /opt/OV/bin/OpC/opcragt odxgdd01.oddc.chrysler.com
Node odxgdd01.oddc.chrysler.com:
OVO Managed Node status :
-------------------------
OV Control           ovcd                              (438374) is running
OV Performance Core  coda                              (270372) is running
OV Communication Broker ovbbccb                           (368704) is running
OV Config and Deploy ovconfd                           (348384) is running
Subagent EA:
Action Agent         opcacta                           (401518) is running
Logfile Encapsulator opcle                             (413710) is running
Monitor Agent        opcmona                           (356456) is running
Message Agent        opcmsga                           (426214) is running
Message Interceptor  opcmsgi                           (430314) is running
Done.

 

 

 

Please suggest what needs to be done to fix the error.

 

Thanks,

Ramkumar A.

1 REPLY 1
Dennis Handly
Acclaimed Contributor
Solution

Re: Getting "argument expected" error while running the script

>for server in `cat /tmp/test.txt`; do

 

No need for cats: for server in $(< /tmp/test.txt); do

 

>/tmp/test.sh: test: argument expected

 

This probably means your if is bad, missing quotes:

if [ `sudo /opt/OV/bin/OpC/opcragt $server | egrep 'ovbbccb|ovconfd|coda|opcmsga|opcacta|opcmsgi|opcle|opcmona' | awk '{print $(NF-1)}' | grep "isn't" | uniq` = "isn't" ]

 

I would suggest you break this up into two and no need for egrep hammer:

result=$(sudo /opt/OV/bin/OpC/opcragt $server | grep "isn't" | \

grep -e ovbbccb -e ovconfd -e coda -e opcmsga -e opcacta -e opcmsgi -e opcle -e opcmona | awk '{print $(NF-1)}' | uniq)

if [ "$result" = "isn't" ]; then

 

But your immediate problem is the fact that your command didn't return anything and you'll need to quote it, if empty.

 

You can also remove the uniq(1) and just see if there is a "isn't":

sudo /opt/OV/bin/OpC/opcragt $server |

grep -e ovbbccb -e ovconfd -e coda -e opcmsga -e opcacta -e opcmsgi -e opcle -e opcmona |

awk '{print $(NF-1)}' | grep -q "isn't"

if [ $? -eq 0 ]; then