I am new to python so forgive me if I have made a stupid mistake. I am trying to create a script in python3.8 to automate whether or not if a service is running and then take an action from there. So for example if the ssh service is running then I would like the script to send a command for stopping it. However my second statement in the if loop is not getting executed it just outputs the information from the command "service ssh status" and that is it. Can you please help with this?
#!/usr/bin/env python3.8
import os
ssh_status = os.system('service ssh status | grep running')
if ssh_status == 'running':
os.system('service ssh stop')