|
|||||||
Запуск команд с использованием sudo внутри команды без запроса пароля
Время создания: 31.08.2017 21:03
Раздел: Python
Запись: xintrea/mytetra_db_mcold/master/base/1499846075df57a1w6oz/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
#!/usr/bin/env python """ Module contains functions for execute work with deb-packages and execute commands in Linux """ import subprocess import os import sys sudoPassword = 'qwertyuiop' def update_proc(): # work variant command = 'apt-get update' os.popen("sudo -S %s" % (command), 'w').write('15151') def update_proc2(): # best variant command = 'apt-get update' p = os.system('echo %s|sudo -S %s' % (sudoPassword, command)) def ex_sudo_command(command): """ Execute command with rights of root :param command: :return: """ #os.system(command) p = os.system('echo %s|sudo -S %s' % (sudoPassword, command)) def ex_update(): """ Execute apt-get update with root rights :return: """ command = 'apt-get update' ex_sudo_command(command) def install(pack): command = 'apt-get install {0}'.format(pack) ex_sudo_command(command) def launch(): pack = '' command = '' try: if sys.argv[1]: pack = sys.argv[1] if sys.argv[2]: command = sys.argv[2] ex_update() install(pack) ex_sudo_command(command) except: print("Incorrect arguments") def launch2(): pack = 'ksonadmin' command = '/opt/seaproject/ksonadmin/run.sh' try: #if sys.argv[1]: # pack = sys.argv[1] #if sys.argv[2]: # command = sys.argv[2] ex_update() install(pack) ex_sudo_command(command) except: print("Incorrect arguments") if __name__ == '__main__': launch() #ex_update() #subprocess.call(["ls", "-l"]) #ex_sudo_command("ls -l") |
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|