How to Check If a Service That I Don't Know the Name of Is Running on Ubuntu

How to check if a service that I don't know the name of is running on Ubuntu

I don't have an Ubuntu box, but on Red Hat Linux you can see all running services by running the following command:

service --status-all

On the list the + indicates the service is running, - indicates service is not running, ? indicates the service state cannot be determined.

If I started a service with sudo start service_name how do I check (later) if it's running?

Found the answer:

sudo initctl list | grep servicename

Get running services and output the service with versions on linux

#!/bin/bash

listServices(){
/bin/systemctl list-units -t service --state=active --plain --no-legend --no-page |
awk -F[@\.] '{print $1}'
}

CSV

while read -r service;do
rpm -q "$service" --qf '%{NAME}.service;%{VERSION}\n'
done < <(listServices)|grep -v "not installed"

dbus.service;1.10.24
firewalld.service;0.6.3
...

Json:

echo '['
while read -r service;do
rpm -q "$service" --qf '{"name": "%{NAME}.service", "version": "%{VERSION}"\},\n'
done < <(listServices)|grep -v "not installed" |sed '$s/,$//'
echo ']'

[
{
"name": "dbus.service",
"version": "1.10.24"
},
{
"name": "firewalld.service",
"version": "0.6.3"
},
{
...
]

How should I do to check if the service running on a remote host?

OK, finally I need to answer my own question. I just got this verification work and wrote a post for it.



Related Topics



Leave a reply



Submit