I have a Raspberry Pi that I use as a NAS for my local network. It works fine, but when I turn off the router to which the pi is connected, it permanently loses the connection. To be able to connect to the network again it has to be restarted. Therefore I have written this script:#!/bin/bashif ! ping -q -w 1 -c 1 $(ip r | grep default | cut -d ' ' -f 3)then        service networking restart        sleep 60        if ! ping -q -w 1 -c 1 $(ip r | grep default | cut -d ' ' -f 3)        then                reboot        fifiIt basically tries to ping the router. If it fails it restarts the networking service (for when a simple error occurred and a reboot is not necessary). If it then still can't ping to the router it reboots. I set this up as a cronjob every 10 minutes, but it does not work. What am I doing wrong?I put this line in the crontab:0,10,20,30,40,50 * * * * /root/rebooter.sh >> rebooter.log 2>&1Whit no connection this is the output:Usage: ping [-LRUbdfnqrvVaAD] [-c count] [-i interval] [-w deadline]            [-p pattern] [-s packetsize] [-t ttl] [-I interface]            [-M pmtudisc-hint] [-m mark] [-S sndbuf]            [-T tstamp-options] [-Q tos] [hop1 ...] destination/root/rebooter.sh: Line 5: service: Command not found.Usage: ping [-LRUbdfnqrvVaAD] [-c count] [-i interval] [-w deadline]            [-p pattern] [-s packetsize] [-t ttl] [-I interface]            [-M pmtudisc-hint] [-m mark] [-S sndbuf]            [-T tstamp-options] [-Q tos] [hop1 ...] destination/root/rebooter.sh: Line 11: reboot: Command not found.With connection this is the output:PING 192.168.178.1 (192.168.178.1) 56(84) bytes of data.--- 192.168.178.1 ping statistics ---1 packets transmitted, 1 received, 0% packet loss, time 0msrtt min/avg/max/mdev = 0.985/0.985/0.985/0.000 ms
Reboot when no network connection does not work!
bash;networking;cron;raspberry pi;reboot