Page 1 of 1

running bash script to reboot raspberry pi

PostPosted: Thu Aug 08, 2019 5:05 am
by spawnreaper
Hello,

I am trying to add a shell script to one of my rules that logs into my raspberry pi using ssh and gives a "shutdown -r" command.
I have tried several options but none seem to work. Since I do not see any errors either I can't figure out what is going wrong.

Code: Select all
ssh pi@192.168.178.91 '/bin/bash -c "sudo shutdown -r now"'
USERNAME="username"
PASSWORD="password"


Code: Select all
ssh pi@192.168.178.91
/bin/bash -c "sudo shutdown -r now"

(I don't need a username and pass to login.)

Code: Select all
ssh pi@192.168.178.91
USERNAME="username"
PASSWORD="password"
'/bin/bash -c "sudo shutdown -r now"'


can someone give me a hint?

Re: running bash script to reboot raspberry pi

PostPosted: Thu Aug 08, 2019 11:01 am
by Mr_Noodle
Have you tried the script outside of Hazel? Also, make sure to use full paths for everything as you can't assume the PATH variable is set to something you expect. Lastly, turn on debug logging as described here: https://www.noodlesoft.com/kb/hazel-debug-mode/

That should provide more output in the logs.

Re: running bash script to reboot raspberry pi

PostPosted: Fri Aug 09, 2019 5:34 pm
by luomat
You definitely want to setup ssh so that you can login without a password, and then you may need to add 'shutdown' to the 'sudoers' file on the Pi, assuming they have such a thing.

Once you can do this in Terminal.app without anything else:

ssh pi@192.168.178.91 'sudo shutdown -r now'

then you can do the same in Hazel.

If you add your public SSH key from your Mac to the '~pi/.ssh/authorized_keys' file you should be able to login without a password.

If you put something like this in your ~/.ssh/config *on your Mac*:

Host mypi
HostName 192.168.178.91
User pi

then you should be able to just type 'ssh mypi' and login to the Pi as the user 'pi' (you can change 'mypi' to anything you want, I just wanted to differentiate it from the username 'pi'.

Once all that is working you should be able to run your reboot command like this:

ssh mypi 'sudo shutdown -r now'

Last but not least you'll want to run

ssh-add -K

on your Mac to add the passphrase to the OS X keychain so you don't need to add it each time you reboot the Mac.