TS239ProII+ & QTS 4.2.4
I try to run the pinging script for ping network devices (smartphone), but it does not work and I get in the log:
Code: Select all
grep: invalid option -- w
BusyBox v1.01 (2017.03.12-18:58+0000) multi-call binary
Usage: grep [-ihHnqvs] PATTERN [FILEs...]
Search for PATTERN in each FILE or standard input.
Options:
-H prefix output lines with filename where match was found
-h suppress the prefixing filename on output
-i ignore case distinctions
-l list names of files that match
-n print line number with output lines
-q be quiet. Returns 0 if result was found, 1 otherwise
-v select non-matching lines
-s suppress file open/read error messages
Code: Select all
#!/bin/sh
#set up new vars;
new_var=0
var1=android
var2=192.168.1.35
ddd=$(date +"%Y-%m-%d %H:%M:%S,%3N")
echo "datetime = $ddd"
echo "ipaddress to check is $var2"
status=`ping -qc 1 $var2 | grep -wi '[0-9][[:space:]]received'|awk -F, '{print $2}'|awk '{print $1}'`
echo "$var1 status is :$status";
# if status is ge 1 that means one of the ips responded to a ping.
# therefore value in pingsensor table should be set to 0;
if [[ $status -gt 0 ]]; then
echo "ping response received resetting $var1 status to 1"
echo "1" > /share/MD0_DATA/.qpkg/OpenRemote/OpenRemote/facts/sensor_$var1
else
#write out a 0 in the android_sensor file
echo "0" > /share/MD0_DATA/.qpkg/OpenRemote/OpenRemote/facts/sensor_$var1
fi
ddd=$(date +"%Y-%m-%d %H:%M:%S,%3N")
echo "datetime = $ddd"
echo "**********************************************************"
Thanks.