Exec not work

in .rules:

rule "L11"
		Item L11 received command
	    val String result=executeCommandLine("ping -c 4 google.com | grep \'received\' | awk -F \',\' \'{ print $2}\' | awk \'{ print $1}\'", 15000)


2016-09-06 13:35:34.941 [INFO ] [org.openhab.model.script.Exec ] - ping: invalid option -- 'F'
Usage: ping [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
            [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
            [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
            [-w deadline] [-W timeout] [hop1 ...] destination

Why he misses grep and awk?
I can write any words between ping and -F, and he does not care. The same error.
"@@" Does not help.

Hello, this can be solved multiple ways.

  • you should be able to find the right solution with “@@”, sorry I can’t tell for sure without testing
  • you can create an extra script file pingtest.sh and call this one to avoid using “@@”
  • you can abandon grep and awk all together and just do the preprocessing in “java-like” xtend syntax in your rules file

Why are you interested in the count of packages received? If you want to know if you are online you can use the network binding, you might also want to look at the speedtest example

Thanks for the answer.

It works like this:

val String result=executeCommandLine("/bin/sh@@-c@@ping -c 4 google.com |grep \"received\" | awk -F \',\' \'{ print $2}\' | awk \'{ print $1}\'", 15000)