I'm trying to get a script together to ssh through a list of hosts and test if a certain process is running and then print out for each host whether or not the process is running. Here is an example:
from fabric.api import *
import getpass
env.user = user'
env.password = getpass.getpass(prompt='Password: ', stream=None)
env.hosts = ['localhost']
def uptime():
run("uptime")
def getinfo():
hostname = run("hostname")
run("ps aux | grep -i apache")
The problem here is that there are multiple processes named apache so it's outputting a huge list rather than just saying something to the effect of "Apache is running on host1" as it goes through the list of servers. How could I either use python to format the output this way or do it in Linux as a part of the actual shell command (ps aux | grep -i apache)?