Put the hostnames or IP addresses in a file named inventory.txt
like this:
computer1 computer2 192.168.1.1
Use this script:
while read host; do ssh root@$ shutdown -h now done < inventory.txt
У меня есть лаборатория и в том, что коллекция компьютеров Linux подключена к локальной сети. Я хочу, как написать сценарий оболочки, чтобы закрыть все ПК, когда мы запускаем этот сценарий оболочки.
Put the hostnames or IP addresses in a file named inventory.txt
like this:
computer1 computer2 192.168.1.1
Use this script:
while read host; do ssh root@$ shutdown -h now done < inventory.txt
I apologize I am not allowed to add a comment (not high enough rep?) so unfortunately have to post this as an answer
I'm curious too why answer was voted down too. There are a lot of merits in what @Cristian is answering and I agree that if OP doesn't have SSH daemon he would either state he needs a workaround OR he would realize maybe he needs it installed. Considering most of the answers for this type of thing would use SSH daemon I think it's a good answer.
That being said, I also agree that you should use root to do this and use ssh key authentication. That's the best and most secure answer. Of course you do not use a password in an ssh script - harder to do (probably would need to use expect) and less secure.
I don't know about using a non-root user to do a poweroff/reboot. Using the link you sent, you realize that the sudo user is configured to have no password and then poweroff the machine. That means any user that knows the username can sudo to that user and poweroff. Is that what you really want?
Apologies again that this is posted as a separate answer - I want to add it as a comment to @Cristian's answer as his answer is one I would vote for