• 下面是通过 AppleScript 执行的脚本:
bash-3.2$ cd /Users/jack/Desktop/
bash-3.2$ ls -l | grep static
-rwxrwxrwx 1 jack admin 65 5 May 08:10 static-routes.sh
bash-3.2$ cat static-routes.sh
#!/bin/bash
sudo route -n add -net 192.168.3.0/24 172.16.254.134
~
• AppleScript 包含以下内容:
do shell script "~/Desktop/static-routes.sh"
• 从AppleScript 中执行脚本时,通过单击“运行”按钮,弹出窗口说:
• 从不带 的控制台执行脚本时sudo
,不会出现其他提示:
bash-3.2$: Desktop jack$ ./static-routes.sh
add net 192.168.3.0: gateway 172.16.254.134
• 以下是摘录/etc/sudoers
:
bash-3.2$ sudo visudo
# root and users in group wheel can run anything on any machine as any user
root ALL = (ALL) ALL
%admin ALL = (ALL) ALL
jack ALL = (ALL) NOPASSWD: /Users/jack/Desktop/static-routes.sh
## Read drop-in files from /private/etc/sudoers.d
## (the '#' here does not indicate a comment)
#includedir /private/etc/sudoers.d
Defaults timestamp_timeout=60
问题:
• 为什么会出现此错误,因为我已将脚本显式添加到 sudoers 文件中,以便通过 sudo 无需密码提示即可执行?
• AppleScript 使用哪个用户来执行脚本?是否可以修改它?