Shutdown via SSH

I wrote a bash script to shut this down for me during a proc of my APC UPS. Problem was that issuing the straight command was hanging up bash, so…

My solution on Ubuntu Server (the machine that will shut down all other computers and Virtual Machines on my network), that my UPS communicates with:

sudo -s

apt-get install sshpass -y

nano /root/.ssh/NASpass

Type your Mycloud’s SSH password and then save the document ( ctrl+x → y → enter )

chown 600 /root/.ssh/NASpass

mkdir /root/scripts

nano /root/scripts/shutdown_NAS.sh

copy paste the following script (making sure to change the IP address to w/e your NAS is) and save it:

#!/bin/bash

sshpass -f /root/.ssh/NASpass ssh root@XXX.XXX.X.XXX "shutdown.sh"

Issue the following command from bash terminal…

timeout 30 /root/scripts/shutdown_NAS.sh

it will shutdown the NAS and then not hang up the bash

you can then put the command inside other scripts if you want (can only be run as root on your host machine, though, unless you’re cool with having the password for your NAS dangling out there…)

Hope this helps!