applescript中的多个shell命令-如何只要求一次密码?

j8yoct9x  于 2023-06-30  发布在  Shell
关注(0)|答案(1)|浏览(118)

我有一个脚本来设置路由到路由表并打开一个应用程序。它工作得很好,做的工作。
问题是有些命令需要sudo权限,因此当我运行脚本时,我被要求多次输入密码。如何使脚本只询问一次密码?在这里查看代码的摘录:

-- delete current routes and store output in variable
set del1 to do shell script "sudo route delete " & MyURL_IP
set del2 to do shell script "sudo route delete " & MyURL_IP2
beep -- one beep for deleting the routes first

-- add new routes to table and store output in variable
set add1 to do shell script "sudo route -nv add " & MyURL_IP & " " & IPAdrGatway & "| grep 'add host'"
set add2 to do shell script "sudo route -nv add " & MyURL_IP2 & " " & IPAdrGatway & "| grep 'add host'"
beep -- one beep for adding new routes

-- create and write to logfile on desktop with timestamp
set the logFile to ((path to desktop) as text) & "RouteAirmail.log.txt"
try
    open for access file the logFile with write permission
    write (return & (current date) & return) to file the logFile starting at eof
    write (del1 & return & del2 & return & add1 & return & add2 & return) to file the logFile starting at eof
    close access file the logFile
on error
    try
        close access file the logFile
    end try
end try

这些命令需要输入pwd:
1.删除现有路由时的密码请求
1.添加路由时
1.写入日志文件时
我尝试了不同的选择,例如。运行一切作为一个shell脚本,但似乎不是那么优雅给我。

piv4azn7

piv4azn71#

删除« sudo »并使用
做shell脚本“命令”用户名“用户名”密码“通行证”与管理员权限

相关问题