Applescript 在 ssh 连接中确认 sudo 密码 [英] Applescript confirm sudo password in ssh connection

查看:30
本文介绍了Applescript 在 ssh 连接中确认 sudo 密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 applescript 打开到 Ubuntu Box 的 ssh 连接.我如何提供 apt 询问的 sudoer 密码:

I´m opening a ssh connection to an Ubuntu Box with applescript. How can I provide the sudoer password asked by apt:

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

推荐答案

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 的完整路径.如果你坚持在终端中运行它,那么你就必须编写一个expect脚本.

You'll have to add the full path to apt-get in the do shell script. If you insist of running it in the terminal, then you'll have to write an expect script.

这篇关于Applescript 在 ssh 连接中确认 sudo 密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆