Hey everybody, this is my firtst post here
I’m trying to shutdown my NAS using a command line switch. I placed a ssh key in the config folder. As you see, i used full pathes… well not for echo…and sleep… Do you have an idea whats wrong? The boot script works perfectly. Both scripts also run perfectly when logged in via ssh.
Code in configuration.yaml
- platform: command_line switches: nas: command_off: /config/script/poweroff_freenas.sh command_on: /config/script/boot_freenas.sh friendly_name: NAS
Bash Script poweroff_freenas.sh
#!/bin/bash
# Shutdown Freenas
while [[ "$(/usr/bin/ssh [email protected] -i /config/.ssh/freenasshutdown)" != *"Shutdown NOW!"* ]]
do
echo
echo "`/bin/date`"
echo "Freenas does not respond to shutdown signal, yet!"
echo
sleep 1
done
echo "Seems like Freenas is preparing shutdown."
while [[ "$(/bin/ping -c 1 freenas.fritz.box)" == *"1 packets received"* ]]
do
echo
echo "`/bin/date`"
echo "Freenas still up!"
echo
sleep 1
done
echo
echo "`/bin/date`"
echo "Freenas appears to be offline"
echo
sleep 45
curl -s -o /dev/null -X POST -H "x-ha-access: password" -H "Content-Type: application/json" -d '{"entity_id": "switch.naspower"}' http://hassio.fritz.box:8123/api/services/switch/turn_off
Bash Script to boot (actually not needed but this one works)
#!/bin/bash
echo “Start NAS!”
curl -s -o /dev/null -X POST -H “x-ha-access: password” -H “Content-Type: application/json” -d ‘{“entity_id”: “switch.naspower”}’ http://hassio.fritz.box:8123/api/services/switch/turn_on