Applescript在ssh连接中确认sudo密码

时间:2015-01-31 15:16:11

标签: applescript

我正在使用applescript打开与Ubuntu Box的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

2 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

无需密码。设置安全的RSA密钥,您将永远不必再次执行此操作。然后你的Applescript将在没有密码的情况下运行。

https://help.ubuntu.com/community/SSH/OpenSSH/Keys