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

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