aleksey_z

Скрипт пингования в DSM 6

Recommended Posts

Всем привет.

 

На DSM 5.1 запускался такой скрипт, который пинговал определенный хост:

 

#!/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 -vi '[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" > /volume1/@appstore/OpenRemote/facts/sensor_$var1
  else
   #write out a 0 in the android_sensor file
   echo "0" > /volume1/@appstore/OpenRemote/facts/sensor_$var1
  fi

ddd=$(date +"%Y-%m-%d %H:%M:%S,%3N")
echo "datetime = $ddd"
echo "**********************************************************"

 

и соответственно записывал в /volume1/@appstore/OpenRemote/facts/sensor_android 0 или 1

 

После обновления на DSM 6.0.1, скрипт выполняется, но в /volume1/@appstore/OpenRemote/facts/sensor_android записывается все время 0, хотя хост нормально пингуется с РС. Как проверить/подправить, почему перестал пинговаться со скрипта?

 

в логе:

datetime = 2016-09-06 15:41:02,142
ipaddress to check is 192.168.1.35
android status is :
datetime = 2016-09-06 15:41:02,401
**********************************************************
datetime = 2016-09-06 15:41:07,145
ipaddress to check is 192.168.1.35
android status is :
datetime = 2016-09-06 15:41:07,418
**********************************************************
datetime = 2016-09-06 15:41:12,150
ipaddress to check is 192.168.1.35
android status is :
datetime = 2016-09-06 15:41:12,330
**********************************************************
datetime = 2016-09-06 15:41:17,153
ipaddress to check is 192.168.1.35
android status is :
datetime = 2016-09-06 15:41:17,454
**********************************************************
datetime = 2016-09-06 15:41:22,157
ipaddress to check is 192.168.1.35
android status is :
datetime = 2016-09-06 15:41:22,264
**********************************************************

 

а было и должно быть (при доступности хоста) так:

datetime = 2016-09-01 09:45:01,%3N
ipaddress to check is 192.168.1.35
android status is :


1
ping response received resetting android status to 1
datetime = 2016-09-01 09:45:01,%3N
**********************************************************
datetime = 2016-09-01 09:45:06,%3N
ipaddress to check is 192.168.1.35
android status is :


1
ping response received resetting android status to 1
datetime = 2016-09-01 09:45:06,%3N
**********************************************************
datetime = 2016-09-01 09:45:11,%3N
ipaddress to check is 192.168.1.35
android status is :


1
ping response received resetting android status to 1
datetime = 2016-09-01 09:45:11,%3N
**********************************************************
datetime = 2016-09-01 09:45:16,%3N
ipaddress to check is 192.168.1.35
android status is :


1
ping response received resetting android status to 1
datetime = 2016-09-01 09:45:16,%3N
**********************************************************

Share this post


Link to post
Share on other sites

Решил. В строке:

 

status=`ping -qc 1 $var2 | grep -vi '[0-9][[:space:]]received'|awk -F, '{print $2}'|awk '{print $1}'`

 

вместо -vi написал -wi и заработало. Хотя изначально скрипт был с -wi, менял на -vi для работы в DSM 5.1.

Share this post


Link to post
Share on other sites