I have a shell script which I used to run for a quick process check mechanism in my Linux environment. Below is just one piece of code which I am using.
How we can achieve the same in Python? I just searched and found to use the "subprocess" module for this purpose, will that be good enough?
Check_ntp () {
echo "Checking the NTP Service Status on $(uname -n)"
ps -e | grep ntp > /dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "Service Status: NTP Service is Running"
else
echo "Service Status: NTP Service is Not Running"
fi
}
Update
I found the answer to my question myself:
#!/usr/bin/python
import subprocess
PSNTP = subprocess.call('ps -e| grep ntp > /dev/null 2>&1', shell=True)
if PSNTP == 0:
print "Status: NTP Service is Running"
else:
print "Status: NTP Service is not Runningg"
PSNSCD = subprocess.call('ps -e | grep nscd > /dev/null 2>&1', shell=True)
if PSNSCD == 0:
print "Status: NSCD Service is Running"
else:
print "Status: NSCD Service is not Running"