[英]Why can't I use 'sudo su' within a shell script? How to make a shell script run with sudo automatically
[英]How to make Automator run Shell Script that requires sudo password?
我使用下面的這個腳本在每次運行時隨機更改 mac 地址。
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' | xargs sudo ifconfig en0 ether
ifconfig en0 | grep ether
我想讓 Automator 為我做這件事。 當我運行這個 Shell 腳本時,它運行成功但是當我實際打開終端並運行時
ifconfig en0 | grep ether
看看它是否改變了 MAC 地址,我發現它沒有。
如果我手動將這樣的腳本輸入終端,它就可以完美運行。 我該怎么辦?
嘗試創建一個AppleScript
:
on run {input, parameters}
do shell script "openssl rand -hex 6 | sed 's/\\(..\\)/\\1:/g; s/.$//' | xargs sudo ifconfig en0 ether" with administrator privileges
do shell script "ifconfig en0 | grep ether"
return input
end run
它應該要求您輸入管理員密碼,然后更改 mac 地址。 Automater 通常更適合運行 Applescript,因為 shell 腳本有時會出現問題。
您可以將它們直接放在root
目錄中。 您需要具有 root 權限才能訪問該功能,但不需要輸入密碼短語。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.