1

I have a script to shutdown the computers in my classroom running Ubuntu 22.04. The script shuts down all the computers, but hangs and does not close. If there something else I should add to the script or change. hothost is a file with the IP addresses of the computers I wish to turn off.

#!/bin/bash while read host; do sshpass -p 123456 ssh "root@$host" shutdown -h now & done < hothost 

2 Answers 2

1

I would use sshkeys instead of passwords. I would also shutdown -h +1 to schedule shutdown for 1 minute in the future, to give my script time to exit prior to executing the shutdown. If it still hangs i would recommend logging in to a targets main terminal when this script is shutting it down and see what is hanging

1
  • Thanks, will do. Commented Oct 16, 2022 at 16:27
1

I put a < /dev/null in the script and it fixed the issue

 #!/bin/bash while read HOST ; do sshpass -p 123456 ssh "root@$HOST" "hostname; shutdown now " < /dev/null; done < hothost 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.