0

So basicly i need to scan my access point every 10 minutes. This job is done by using this command

ssid=iw wlan0 scan | grep -E 'MY SSID NAME'

The output like this

SSID: MY SSID NAME

But when i add some if-else using the output command above, it fails

if [[ $ssid == "SSID: MY SSID NAME" ]]
then
echo "SSID Detected"
else
echo "SSID NOT Detected"
fi

it will return false statement ("SSID NOT Detected"). The fact is, my SSID available and broadcasting. Need help.
And Thank you :)

  • 3
    See: [How to set a variable equal to the output from a command in Bash?](http://stackoverflow.com/q/4651437/3776858) – Cyrus Jul 02 '16 at 04:25
  • Still no luck. Change variable to this : ssid=`iw wlan0 scan | grep -E "MY SSID NAME"` (adding backticks) on variable value. Still go straight to false condition – Andika Trisna Adhi Jul 02 '16 at 04:48
  • 2
    This might help: [How to debug a bash script?](http://unix.stackexchange.com/q/155551/74329) – Cyrus Jul 02 '16 at 05:32
  • What does `echo "@$ssid@"` print? Any spaces around the string `SSID: MY SSID NAME`? – anishsane Jul 02 '16 at 05:45

1 Answers1

3

You can test the exit status of grep instead of the result, that is

if iw wlan0 scan | grep -q 'MY SSID NAME'; 
then echo "Detected"; 
else echo "Not Detected"; 
fi
karakfa
  • 66,216
  • 7
  • 41
  • 56