Ticket #1128 (new)

Opened 5 years ago

Last modified 5 years ago

Ping watchdog for telecontrol

Reported by: Musti Owned by: Musti
Priority: normal Milestone:
Component: telemetry Version:
Keywords: Cc:
Related nodes: Realization state:
Blocking: Effort: normal
Blocked by: Security sensitive: no


Develop a ping watchdog that triggers a reset of a specified channel via readsensor communication script.

Resets after 15min if more then 90% packet loss.


ping-watchdog.sh (492 bytes) - added by ziga.z 5 years ago.

Change History

comment:1 Changed 5 years ago by Musti

Solution developed by ziga.z

Pings every second, after 1000pings (or wahtever is set) the script will send reset if more then 90% packet loss or if not restart itself. It does not restart after a reset.

# usage: test.sh 5

# IP as first argument

# 1000s = 16 min, 40 seconds

# wait max 1 second for reply

# readsensor argument

PACKET_LOSS=`ping -c $PING_COUNT -W $PING_TIMEOUT $IP | grep 'packet loss' | cut -d% -f 1 | cut -d" " -f7`
if [ $PACKET_LOSS -gt 90 ]; then
  readsensor -d /dev/ttyS0 -i $IARG -s 0
  sleep 5
  readsensor -d /dev/ttyS0 -i $IARG -s 1
  sleep 10
  `which ash` $0 "$@"

comment:2 Changed 5 years ago by kostko

This line seems suspect:

`which ash` $0 "$@"

I see that you want to run the watchdog over and over, but you are instantiating more and more shell script interpreters as the parent process never finishes. This is bad as it uses more and more resources.

Why don't you use a loop – something like:

while (( 1 )); do
  PACKET_LOSS=`ping ...`
  if [ $PACKET_LOSS -gt 90 ]; then
    readsensor ...
    sleep 5
    readsensor ...
    sleep 10

Changed 5 years ago by ziga.z

Note: See TracTickets for help on using tickets.