首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >一次远程重启多台Mac

问一次远程重启多台Mac
EN

Stack Overflow用户
提问于 2012-01-30 01:28:27
回答 2查看 138关注 0票数 1

我们有一个由9台Mac组成的网络,我想一下子把它们全部关闭。现在我正在使用这个AppleScript,但正如您所看到的,它使用SSH逐个关闭计算机。如果其中一个已经关闭,脚本将会冻结。有没有办法让我一次关闭所有的Mac?

代码语言:javascript
复制
set finalIP to 100
repeat until finalIP is 109
tell application "Terminal"
    activate
    set success to 0
    do script "echo Rebooting.."
    do script "ssh -l username 192.168.1." & finalIP in front window
    delay 1
    repeat until success = 1
        if last word of (contents of front window as text) = "no" then
            do script "yes" in front window
            delay 1
        else if last word of (contents of front window as text) = "password" then
            do script "password" in front window
            set success to 1
            do script "echo About to reboot.." in front window
        else
            delay 1
        end if
    end repeat
    do script "sudo reboot" in front window
    repeat until last word of (contents of front window as text) = "password"
        delay 1
    end repeat
    do script "password" in front window
    close front window
end tell
set finalIP to finalIP + 1
delay 1
end repeat
tell application "Terminal" to quit
EN

回答 2

Stack Overflow用户

发布于 2012-01-30 01:35:17

您可以简单地为ssh连接设置一个超时:

代码语言:javascript
复制
ssh -o ConnectTimeout=10 -l ...

(这是10秒超时,请根据需要进行调整。)

另外,还可以考虑使用键进行连接。确实没有充分的理由将SSH密码放在脚本中。(如果您这样做了,还要添加-o BatchMode=yes选项-它将跳过您无法使用密钥登录的主机。)

票数 1
EN

Stack Overflow用户

发布于 2012-01-30 01:39:46

-o标志允许您指定一个超时时间,这样当它在指定的秒数之后没有成功连接时,它将中止。

代码语言:javascript
复制
imac$ ssh -o ConnectTimeout=5 123.45.6.7
ssh: connect to host 123.45.6.7 port 22: Operation timed out
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9055147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档