Sunday, September 7, 2025

Service Check

I thought about a simple way of checking if a service is installed and running.  Below is the script for it. 

#!/bin/bash
read -p "Enter service name to check: " ServiceName

# Alternative using grep, uncomment line 5 and comment line 8
#if which "$ServiceName" &>/dev/null; then if ps -aux | grep -v grep | grep -q "$ServiceName"; then echo "$ServiceName is installed and running"; else echo "$ServiceName is installed, but not running"; fi; else echo "$ServiceName is not installed"; fi

# Alternative using pgrep, uncomment line 8 and comment line 5
if which "$ServiceName" &>/dev/null; then if pgrep -c "$ServiceName" > 0; then echo "$ServiceName is installed and running"; else echo "$ServiceName is installed, but not running"; fi; else echo "$ServiceName is not installed"; fi

Feel free to comment if you have a suggestion to make it simpler

Regards,

F. Bobbio C.