summaryrefslogtreecommitdiff
path: root/reboot-if-no-net-connection.in
blob: b1d41fb9a296a338444c4a9963620176853656bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash

# Version #VERSION#

for i in {1..300}; do

  default_gateway=$(
    ip route \
    | sed '
      s/^default\s\+\S\+\s\+\(\S\+\)\s.*$/\1/
      t
      d
    '
  )

  if [ -n "${default_gateway}" ] \
  && ping -c1 "${default_gateway}" >/dev/null 2>&1; then
    exit
  fi

  sleep 1

done

reboot