-1

I would like to make a shutdown-script for my raspberry pi to shut down anothe raspberry pi over ssh.

The script works if it is running itself but at the shutdown routine the ssh command is not executed.

So that I have done until now:

  1. Made the script in /etc/init.d:
 #!/bin/sh
 # the first thing is to test if the shutdown script is working
 echo "bla bla bla " | sudo tee -a /test.txt  
 ssh pi@10.0.0.98 sudo shutdown -h now
  1. Made it executable
sudo chmod +x /etc/init.d/raspi.sh
  1. Made a symlink to the rc0.d
sudo ln -s /etc/init.d/raspi.sh /etc/rc0.d/S01raspi.sh

Now I know so far that the shutdown script is working outside of the shutdown routing by calling itself and the shutdown symlink I made is also working partially because I see the changes in the test.txt file every time I shut down.

Can anyone help me how to solve my problem?

Fabian
  • 403
  • 5
  • 13

3 Answers3

1

Have you tried with single quotes? The first link in Google has it

http://malcontentcomics.com/systemsboy/2006/07/send-remote-commands-via-ssh.html

What about the sudo, how do you solve entering the password?

https://superuser.com/questions/117870/ssh-execute-sudo-command

Please check this or other links on the web that have useful information.

I would have send all this in a comment but I cant yet because of reputation.

Community
  • 1
  • 1
Carlos
  • 1,340
  • 1
  • 10
  • 26
  • I solved the problem with entering the password at ssh with a key and for the sudo at shutdown there is no password necessary. I tried the method with the single quotes as in the first link suggested and the adding of -t to the ssh command as suggested in the second link. I also tried the method with "update-rc.d raspi.sh stop 01 0" that I found on a second search on the internet but there is the same output than described at the question. – Fabian Feb 08 '16 at 21:16
0

I have now got the script running by myself. I do not really know why it is now working but I write it down beneath and maybe someone else can clearifiy it.

I don´t think the first two changes at my system makes a difference but I also write it down. In the meanwhile because I do not managed the script to get working I had made a button to shutdown the system manually. Also I made a script which backs the mysql-database up (which is on the Raspberry Pi which I would like to switch off with the script) and copies the backup to the raspberry pi which should switch of the other raspberry automatically via the shutdown-script. This happens with scp and also for the password is a key generated.

I have also changed my script to get a log-message out of the script.

#!/bin/sh
ssh -t -t pi@10.0.0.99 'sudo shutdown -h now' >> /home/osmc/shutdown.log 2>&1

To get it into the shutdown-routine I used:

sudo update-rc.d raspi-b stop 01 0

I hope somebody can say me why my code now worked on the first day but not on the next few days until now.

Fabian
  • 403
  • 5
  • 13
0

I structured a command to suspend or shutdown a remote host over ssh. You may find this useful. This may be used to suspend / shutdown a remote computer without an interactive session and yet not keep a terminal busy. You will need to give permissions to the remote user to shutdown / suspend using sudo without a password. Additionally, the local and remote machines should be set up to SSH without an interactive login. The script is more useful for suspending the machine as a suspended machine will not disconnect the terminal.

local_user@hostname:~$ ssh remote_user@remote_host "screen -d -m sudo pm-suspend"

source: कार्यशाला (Kāryaśālā)

Lord Loh.
  • 2,437
  • 7
  • 39
  • 64