I need to execute a bash script from a python program (python2.7) in red hat, while this bash script has to run from another user account as splunk user.
In the Linux, I will switch to splunk user su - splunk
first, then type the command ./mybashFile
under as a splunk user
Here is what I tried:
import subprocess
cmd1=subprocess.Popen(["su","-","splunk"],shell=True,stdout=subprocess.PIPE)
cmd2=subprocess.Popen(["./path/myBashFile.sh"],shell=True,stdin=cmd1.stdout,stdout=subprocess.PIPE)
cmd2.stdout
I still cannot run this bash file from as a splunk user. This command cannot pass to another account.