Applescript确认ssh连接中的sudo密码

Applescript确认ssh连接中的sudo密码,applescript,Applescript,我正在用applescript打开一个到Ubuntu盒的ssh连接。如何提供apt要求的sudoer密码: tell application "Terminal" set currentTab to do script ("ssh -p" & pnumber & " " & user & "@localhost;") delay 2 do script ("sudo apt-get update") in curre

我正在用applescript打开一个到Ubuntu盒的ssh连接。如何提供apt要求的sudoer密码:

tell application "Terminal"
        set currentTab to do script ("ssh -p" & pnumber & " " & user & "@localhost;")
        delay 2
        do script ("sudo apt-get update") in currentTab

        -- start provide here password for sudo
        -- this ends in keystroke cannot be read
        keystroke "password"
        keystroke return
        -- end provide password

        do script ("exit;") in currentTab
    end tell

不需要密码。设置一个安全的RSA密钥,您就再也不必这样做了。然后您的Applescript将在没有密码的情况下运行


您必须在do shell脚本中添加apt get的完整路径。如果您坚持在终端上运行它,那么您必须编写一个expect脚本。

当然可能重复,但在某些情况下您无法更改服务器身份验证;)
try
    set resultText to (do shell script "apt-get update" with administrator privileges)
on error e number n 
    tell application (path to frontmost application as text )
        display alert "Something went wrong: " & e & " nr: " & n
    end tell
    error number -128
end try
tell application (path to frontmost application as text)
    display alert resultText
end tell