尝试运行使用SUDO SU-并将控制权传递给shell以运行ksh脚本的python脚本。它工作得很好,但是stdout给了我一个我想要解决的错误
通过ANSIBLE Tower或直接调用:python测试.py纽帕斯
#!/usr/bin/env python
'''
Python script for Oracle
Called by the following
SYS_SYSTEM_PASSWORD_CHANGE {{PASSWD}}
'''
import os
import sys
import re
import argparse
import textwrap
import subprocess
#import commands
# RUNPROC process.
def runproc():
print('RUNNING PASSWORD CHANGE')
cmds = ['sudo su - ' +runas +'/orasoft/scripts/password_change.ksh ' +npass]
p = subprocess.Popen('/bin/bash', shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
for cmd in cmds:
print(cmd)
p.stdin.write(cmd)
p.stdin.close()
print(p.stdout.read())
def get_command():
parser = argparse.ArgumentParser(prog='PROG',formatter_class=argparse.RawDescriptionHelpFormatter,
description=textwrap.dedent('''\
'''))
parser.add_argument('passwd')
args = parser.parse_args()
global npass
npass = args.passwd
print('NEW PASS: ' +npass)
proc = subprocess.Popen("ls -latr /etc/oratab | tr -s ' ' | cut -f3 -d' '",stdout=subprocess.PIPE, shell=True)
global runas
(runas, err) = proc.communicate()
#runas = runas.decode("utf-8")
print('RUNNING AS: ' +runas)
#print(runas.decode("utf-8"))
runproc()
# -- begin fetching commands
get_command()
一切都正确传递,脚本也被正确调用,但我不理解无效参数错误 以下是测试的输出:
^{pr2}$
从sudo su中删除破折号(-)可以解决此错误。 谢谢您!在
相关问题 更多 >
编程相关推荐