This is how I running the bash script set in myscript.sh
#!/bin/bash
import subprocess
child = subprocess.Popen(['bash', '-c', '/bin/bash myscript.sh'], stdout = subprocess.PIPE)
output=child.communicate()
print(output)
myscript.sh
Why am I making this is because the bash script that I have to run does not have the export command so I am echoing here. Code bellow. I know echoing wont set the environment variable but I just want to echo it and fetch the value so echoing instead of exporting.
#!/bin/bash
source ia_servers
echo $IA_SRV_cs68_64
Where, $IA_SRV_cs68_64
Here is the ia_servers file where the variable values are listed it looks something like this
IA_SRV_cs68_64="ds1 ds2 ds3 ds5 "
This is how the variables are in it. Many other variable are set in it eliminated because too longer.
TESTED works well from terminal:
- source ia_servers
- echo IA_SRV_cs68_64
prints the desired values set
Problem: Though myscript.sh is working and printing the variables . What I want is I don't want to create a separate file write a bash script there to echo the variable as in the myscript.sh but instead write it within the python.
How do I accomplish it within the python rather rather than making the script file and run that.