# Exec not work

**URL:** <https://community.openhab.org/t/exec-not-work/13892>\
**Category:** Scripts & Rules\
**Tags:** exec, rules\
**Created:** [September 6, 2016, 11:50am UTC](https://community.openhab.org/t/exec-not-work/13892 "2016-09-06T11:50:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elnur\_Ismailzada](https://community.openhab.org/letter_avatar_proxy/v4/letter/e/e68b1a/32.png) [@Elnur\_Ismailzada](https://community.openhab.org/u/Elnur_Ismailzada)\
**Post date:** [September 6, 2016, 11:50am UTC](https://community.openhab.org/t/exec-not-work/13892/1 "2016-09-06T11:50:34Z")

</div>

in .rules:

```php
rule "L11"
	when 
		Item L11 received command
	then
	    val String result=executeCommandLine("ping -c 4 google.com | grep \'received\' | awk -F \',\' \'{ print $2}\' | awk \'{ print $1}\'", 15000)
	    postUpdate(Ping,result)
            logInfo("Exec",result)
end

```

errors:

```auto
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.

---

<div class="post-metadata">

**Author:** ![ThomDietrich](https://community.openhab.org/user_avatar/community.openhab.org/thomdietrich/32/71239_2.png) [@ThomDietrich](https://community.openhab.org/u/ThomDietrich)\
**Post date:** [September 6, 2016, 1:53pm UTC](https://community.openhab.org/t/exec-not-work/13892/2 "2016-09-06T13:53:59Z")

</div>

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](http://docs.openhab.org/addons/bindings/network/readme.html), you might also want to look at the [speedtest example](https://community.openhab.org/t/speedtest-cli-integration/7611)

---

<div class="post-metadata">

**Author:** ![Elnur\_Ismailzada](https://community.openhab.org/letter_avatar_proxy/v4/letter/e/e68b1a/32.png) [@Elnur\_Ismailzada](https://community.openhab.org/u/Elnur_Ismailzada)\
**Post date:** [September 6, 2016, 3:02pm UTC](https://community.openhab.org/t/exec-not-work/13892/3 "2016-09-06T15:02:32Z")

</div>

Thanks for the answer.

It works like this:

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

```
