├── .github └── FUNDING.yml ├── .gitignore ├── .editorconfig ├── README.md └── power-on-server.sh /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: timothystewart6 2 | patreon: technotim -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | coverage 3 | dist 4 | .idea 5 | .vscode 6 | npm-debug.log 7 | .tmp 8 | .DS_Store 9 | yarn-error.log 10 | temp 11 | public 12 | .log 13 | docs 14 | .nyc_output 15 | cassettes 16 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pi-wol 2 | 3 | It’s the hail Mary of wake on lan commands for my raspberry pi / pi zero. 4 | 5 | I use this to ping my servers and wake them up if they are off. They should never be. 6 | 7 | ## install 8 | 9 | `sudo apt-get install etherwake` 10 | 11 | `sudo apt-get install wakeonlan` 12 | 13 | ## cron job 14 | 15 | `crontab -e` 16 | 17 | `@hourly bash /home/pi/power-on-server.sh > power-on-server.log` 18 | (will run at reboot and will pipe out logs) 19 | 20 | Requires `etherwake` and `wakeonlan` (apt-get). 21 | 22 | Installed `etherwake` and `wakeonlan` beacuse I had some issues with one or the other between updates, so I added both so that I don't have to worry when updating. 23 | 24 | ## Credits 25 | Created by Techno Tim with 💛 26 | 27 | 🔔 Social Media 🔔 28 | 29 | ► Twitch https://www.twitch.tv/TechnoTim 30 | 31 | ► Twitter https://twitter.com/TechnoTimLive 32 | 33 | ► Discord https://l.technotim.live/discord 34 | 35 | ► Instagram https://www.instagram.com/techno.tim/ 36 | 37 | ► Facebook https://www.facebook.com/TechnoTimLive/ 38 | 39 | ► GitHub https://github.com/timothystewart6 40 | -------------------------------------------------------------------------------- /power-on-server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # this runs as a @hourly cron task 3 | #run 4 | # cronetab -e 5 | # @hourly bash /home/pi/power-on-server.sh > power-on-server.log 6 | # requires etherwake and wakeonlan (apt-get) 7 | # installed etherwake and wakeonlan beacuse I had some issues with one or the other between updates, so I added both 8 | 9 | HOSTNUM=0 10 | HOSTS=(192.168.0.1 192.168.0.2 192.168.0.3) 11 | HOSTSDOWN=0 12 | MACADDRS=(mac.address.1 mac.address.2 mac.address.3) 13 | PING="/bin/ping -q -c1" 14 | WAITTIME=10 15 | 16 | ### functions 17 | 18 | function wake_up() { 19 | echo wakeonlan ${MACADDRS[${HOSTNUM}]} 20 | echo wakeonlan -p 9 ${MACADDRS[${HOSTNUM}]} 21 | echo sudo etherwake ${MACADDRS[${HOSTNUM}]} 22 | } 23 | 24 | # first sleep to allow system to connect to network and time to break out if needed 25 | #sleep 60 26 | 27 | for HOST in ${HOSTS[*]}; do 28 | if ! ${PING} ${HOST} > /dev/null 29 | then 30 | HOSTSDOWN=$((${HOSTSDOWN}+1)) 31 | echo "${HOST} is down $(date)" 32 | # try to wake 33 | wake_up ${HOSTNUM} 34 | sleep 10 35 | wake_up ${HOSTNUM} 36 | sleep 10 37 | wake_up ${HOSTNUM} 38 | sleep 10 39 | wake_up ${HOSTNUM} 40 | sleep 10 41 | #restart networking 42 | /etc/init.d/networking reload 43 | sleep 15 44 | # try to wake 45 | wake_up ${HOSTNUM} 46 | sleep 2 47 | wake_up ${HOSTNUM} 48 | sleep 2 49 | HOSTNUM=$(($HOSTNUM+1)) 50 | else 51 | echo "${HOST} was up at $(date)" 52 | fi 53 | done 54 | 55 | # reboot 56 | if [[ ${HOSTSDOWN} -eq ${#HOSTS[@]} ]] 57 | then 58 | echo "Pi is rebooting" 59 | fi 60 | /sbin/shutdown -r now 61 | --------------------------------------------------------------------------------