Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

This question already has an answer here:

I try to run this script against a remote machine, to carry out login check, but have some problems executing it with no errors. I have the following error when I run the script: The Error:

bash: -c: option requires an argument
bash: line 2: [: missing `]'

The Shell Script:

#!/bin/bash
ssh [email protected] bash -c '
radtest user password 127.0.0.1 100 testing | grep 'Access-Accept' &> /dev/null
if [ $? == 0]; then
        echo "match"
fi
'

Any ideas what could cases the error? Note: ssh doesn't need a password here.

share|improve this question

marked as duplicate by Gilles Feb 17 at 23:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
You can compress that to: if radtest user password 127.0.0.1 100 testing | grep -q "Access-Accept"; then ... –  muru Feb 17 at 23:17
    
Thanks for advice, I'll try it. –  Gazel Feb 17 at 23:39

1 Answer 1

up vote 0 down vote accepted

I think this:

if [ $? == 0];

should be:

if [ $? == 0 ];

But as muru suggested it can be:

#!/bin/bash
ssh [email protected] bash -c '"
if radtest user password 127.0.0.1 100 testing | grep -q "Access-Accept"; then
echo "Match"
fi
"'
share|improve this answer
    
Invert the quote order, or $? will be expanded by the current shell. –  muru Feb 17 at 23:16
    
@taliezin Thanks, worked out well. –  Gazel Feb 17 at 23:31
    
sorry I didn't see that error in question I am going to delete this. Or I'll try to edit it. –  taliezin Feb 17 at 23:32
    
@taliezin Ok, so the core is working now but still the fist minor error is there: bash: -c: option requires an argument. However, the main functions are working now. –  Gazel Feb 17 at 23:47
    
I edited it. Sorry did not see he first error. –  taliezin Feb 17 at 23:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.