У меня есть фрагмент кода ниже, чтобы выполнить быструю проверку работоспособности систем и служб, которая работает нормально. Однако я хочу включить проверку с условием elif для call_function
т.е. ps_rpcbind
, поскольку на данный момент яПроверяю rpc
Сервис, работает ли он или нет, с проверкой ps -e | grep rpc
в call_function
, где я хотел бы добавить одно из условий на основе команды rpcinfo -p
для перекрестной проверки того же самого.
Могу ли я добавить это в call_function
import subprocess
import socket
hst_name = (socket.gethostname())
print "HostName:", hst_name
############### Function to Check the Different process & Service Status #########
def call_function(service):
#return subprocess.call('ps -e | grep service> /dev/null 2>&1', shell=True)
return subprocess.call('ps -e | grep %s > /dev/null 2>&1' % service, shell=True)
ps_ntp = call_function("ntp")
ps_nscd = call_function("nscd")
ps_mail = call_function("sendmail")
ps_postfix = call_function("qmgr")
#ps_altris = call_function("aex-plug")
ps_automnt = call_function("automount")
ps_rpcbind = call_function("rpc")
if ps_ntp == 0:
print "Service Status: NTP is Running on the host", hst_name
else:
print "Service Status: NTP is not Running on the host", hst_name
if ps_nscd == 0:
print "Service Status: NSCD is Running on the host", hst_name
else:
print "Service Status: NSCD is not Running on the host", hst_name
if ps_rpcbind == 0:
print "Service Status: Rpcbind is Running on the host", hst_name
else:
print "Service Status: Rpcbind is not Running on the host", hst_name
if ps_mail == 0:
print "Service Status: Sendmail is Running on the host", hst_name
elif ps_postfix == 0:
print "Service Status: Postfix is Running on the host", hst_name
else:
print "Service Status: Sendmail is not Running on the host", hst_name
if ps_automnt == 0:
print "Service Status: Automount is Running on the host" , hst_name
else:
print "Service Status: Automont is not Running on the host" , hst_name
Что необходимо: На основе rpcinfo -p
if ps_rpcbind == 0:
print "Service Status: Rpcbind is Running on the host", hst_name
elif ps_rpc == 0:
print "Service Status: Rpcbind is Running on the host", hst_name
else:
print "Service Status: Rpcbind is not Running on the host", hst_name
Команда rpcinfo -p
возвращает значение ниже выходного.
# rpcinfo -p
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
Пожалуйста, дайте мне знать, если требуется какая-либо информация.