Exec not work

Tags: #<Tag:0x00007fadf83a8ad8> #<Tag:0x00007fadf83a88d0>

(Elnur Ismailzada) #1

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.

( ) #2

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

(Elnur Ismailzada) #3

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)