我的意图是在我的 ip 列表中循环,如果我的 ping 首先成功,则关闭电源。但是系统似乎挂起。运行此脚本后,我无法再对系统执行 ping 操作,它们也没有关机。如果我通过终端运行 ssh 192.168.1.ip "sudo poweroff"
我不会遇到这个问题。有什么建议吗?
for ((ip=40, cnt=0; ip<=max; ip++, cnt++))
do
if ping -c 1 192.168.1.$ip &> /dev/null
then
printf "\n${array[$cnt]}: Ping Successful"
ssh 192.168.1.$ip "sudo poweroff"
printf "\n${array[$cnt]}: Power Down Executed\n"
sleep 1
else
printf "\n${array[$cnt]}: Ping Failed\n"
fi
done
运行单个 ssh 192.168.1.40 "sudo poweroff"
后,系统正确关闭电源。运行我的脚本时,我无法 ping 系统,但我可以直观地看到风扇和 LED 灯仍然亮着。我想我应该使用 KVM 来仔细查看,因为运行此脚本后 ssh 不允许连接。乍一看,我仍然不明白运行 ssh 192.168.1.40 "sudo poweroff"
并通过我的脚本运行它真的有什么不同。不管怎样,我明天会尝试添加更多信息。
最佳答案
ssh 192.168.1.$ip "(sleep 5; sudo poweroff)&" to put the process in the background on the remote host and sleep for 5 seconds before powering off to give time for the script to complete and exit the remote host before it goes down... – David C. Rankin
这解决了我的问题。
关于linux - Bash poweroff 脚本挂起系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47194255/