Applescript 在 ssh 连接中确认 sudo 密码
Applescript confirm sudo password in ssh connection
我正在使用 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
不需要密码。设置一个安全的 RSA 密钥,您将永远不必再这样做。那么你的 Applescript 将 运行 没有密码。
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 脚本。
我正在使用 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
不需要密码。设置一个安全的 RSA 密钥,您将永远不必再这样做。那么你的 Applescript 将 运行 没有密码。
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 脚本。