I am trying to automate an application restarts with Python which is currently implemented with shell scripts. Before running the restart commands, we need to source a .sh environment file which is done in the shell script with . ./opt///**.sh. I am using paramiko and exec_command to run the restart command which throws the error that libraries are missing. So I have tried several ways to source this environment file in the python program but have not been successful.
Things I have tried:
stdin1,stdout1,stderr1 = ssh_client1.exec_command(". ./opt///**.sh")
stdin1,stdout1,stderr1 = ssh_client1.exec_command("source /opt///**.sh")
subprocess.call("/opt///**.sh", shell=True)
os.system(". /opt///**.sh")
I picked the below from stack overflow if I remember correctly
enter code here
command = shlex.split("bash -c 'source /opt///**.sh'")enter code here
proc = subprocess.Popen(command, stdout = subprocess.PIPE)enter code here
for line in proc.stdout:enter code here
(key, _, value) = line.partition("=")enter code here
os.environ[key] = valueenter code here
proc.communicate()
I still get the same error missing libraries which I am supposed to get when I do not source the environment file when I run the application restart commands using exec_command("/opt///start")
Any help is really appreciated.
Thanks.