xxxxxxxxxx
import subprocess
# Replace 'script.sh' with the actual name/path of your bash script
script_path = '/path/to/script.sh'
# Run the bash script
result = subprocess.run(['bash', script_path], capture_output=True, text=True)
# Print the output of the script
print(result.stdout)
xxxxxxxxxx
import subprocess
print "start"
subprocess.call("sleep.sh")
print "end"
xxxxxxxxxx
In the file job.sh, put this
#!/bin/sh
python python_script.py
Execute this command to make the script runnable for you : chmod u+x job.sh
Run it : ./job.sh
xxxxxxxxxx
import subprocess
# Example command that you want to run
command = "ls -l"
# Run the command using subprocess.call() function
subprocess.call(command, shell=True)
xxxxxxxxxx
The simplest approach is to just save the python script as, for example script.py and then either call it from the bash script, or call it after the bash script:
#!/usr/bin/env bash
echo "This is the bash script" &&
/path/to/script.py
Or
script.sh && script.py
xxxxxxxxxx
import subprocess
output = subprocess.check_output('pidstat -p ALL'.split(' '), stderr=subprocess.STDOUT, universal_newlines=True)
print(output)