- 10 Oct 2024
- 1 Minute to read
- Print
- PDF
Check System service
- Updated on 10 Oct 2024
- 1 Minute to read
- Print
- PDF
Use this script to check system service of the device(s) on Linux machines.
Copy and save the contents below to a UTF-8 editor like notepad++ OR Sublime Text in Windows or gedit in Ubuntu.
If you are using notepad++ then use the bottom right panel to change the type to Unix (LF).
Or click here to download the file.
#!/bin/bash # Define the service names to check service_names=("Service1" "Service2") # Function to check the status of a service check_service_status() { local service_name="$1" if systemctl is-active --quiet "$service_name"; then echo "Service $service_name is running." systemctl status "$service_name" elif systemctl list-unit-files | grep -q "^$service_name.service"; then echo "Service $service_name is present but not running." else echo "Service $service_name is not present." fi } # Iterate over the service names and check their status for service_name in "${service_names[@]}"; do check_service_status "$service_name" echo done
In the script, replace the following placeholder:
Provide the service_names in the script.
# Define the service names to checkservice_names=("Service1" "Service2")
The script will show system service status:
Running - Will print the status of service.
If service is present but not running it will mention that.
If service is not present, it will mention that.
You can check status of multiple services in one go.
Follow our guide to upload & publish the script using Scalefusion Dashboard.
Note:
Some of the scripts and their contents are sourced from internet and yes, our new friend ChatGPT.
Please validate the scripts on a test machine before deploying them on all your managed devices.
Scalefusion has tested these scripts, however Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the usage of these scripts.