[英]Execute sudo command non-interactively
我想在沒有交互的情況下執行以下命令:
sudo grep -e "test" /etc/sudoers
我嘗試了以下方法:
tester@compute:~$ echo 'clouduser' | sudo -S grep -e "test" /etc/sudoers
[sudo] password for tester: test ALL=(ALL) NOPASSWD: ALL
問題是我在響應之前獲取了[sudo] password for tester:
的[sudo] password for tester:
。 我怎么能從答案的前面剪掉那部分?
謝謝!
將以下行添加到您的/etc/sudoers
文件以打開無密碼 sudo。 在這種情況下,我使用john
作為登錄帳戶。 更改為您自己的帳戶 ID。
john ALL=(ALL:ALL) ALL
或者,也許更好的是將該行放入名為/etc/sudoers.d/john
的文件中。
我會回答我的問題——也許其他人會需要它:
(echo 'clouduser' | sudo -Si >/dev/null 2>&1); sudo grep -e test /etc/sudoers
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.