Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

Getting "argument expected" errow while running the script

Go to Solution
Respected Contributor [Founder]

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/
for server in `cat /tmp/test.txt`
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" ]
echo "$server has some of the agents in not running state" >> /tmp/problematic_servers.txt
echo "$server is ok"
shcscp18:/clocal/cschpov/user/t1982ra $ sudo /tmp/
Checking the agent health on
/tmp/ test: argument expected

shcscp18:/clocal/cschpov/user/t1982ra $ cat /tmp/test.txt 

shcscp18:/clocal/cschpov/user/t1982ra $ sudo /opt/OV/bin/OpC/opcragt
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




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



Ramkumar A.

Acclaimed Contributor [Founder]

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

[ Edited ]

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


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


>/tmp/ 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