Мне нужно запустить скрипт (text.sh), который требует sudo, без ввода пароля, например:
sudo apt-get update >> /home/derp/test.txt
Я изменил файл sudoers следующим образом:
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL) ALL
pedro ALL=(ALL) NOPASSWD: /home/pedro/Desktop/scripts/test.sh
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
Если я модифицирую этот скрипт, чтобы стать:
time
Выход:
real 0m0.000s
user 0m0.000s
sys 0m0.000s
, как и следовало ожидать.
Я действительно не знаю, что еще делать ...
Сценарий вызывается, потому что я получаю приглашение пароля в консоли, поэтому я не думаю, что это Django или python.
------ EDIT ----- Возможно, вам нужно указать sudo в вызове python, например:
subprocess.call(['sudo', "/your/script.sh"])
и вы можете оставить его вне сценария. Поэтому он исправлен.