如何做一个苹果脚本来进行ssh连接?

时间:2017-01-20 15:04:54

标签: variables ssh applescript

我正在开发一个简单的苹果脚本来帮助进行日常的ssh连接

这是一个例子

tell application "Terminal"
    set ServerName to "IP"
    set ServerUserName to "user"
    set ServerPassword to "password"
end tell

现在,我有疑问。

我如何做ssh username@servername并发送密码?

它是这样的?

do shell script "ssh " & ServerUserName & " @ " & ServerAddress 
dealy 5
keystroke ServerPassword

由于

1 个答案:

答案 0 :(得分:0)

虽然你不应该使用@Jakuje所提到的硬编码密码,但你可以使用这种方法:

tell application "Terminal"
set ServerAddress to "IP"
set ServerUserName to "user"
set ServerPassword to "pw"
end tell

tell application "Terminal"
set currentTab to do script ("ssh " & ServerUserName & "@" & ServerAddress & ";")
delay 5
do script (ServerPassword) in currentTab
end tell

这对你有帮助吗?