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
How to Grep One String Occuring Multiple Times from Same File
Bash Shell Script - Check for a Flag and Grab Its Value
How to Install Crontab on Centos
Shell Init Issue When Click Tab, What's Wrong with Getcwd
Should I Put Trailing Slash After Source and Destination When Copy Folders
Ps Utility in Linux (Procps), How to Check Which CPU Is Used
Loading Module on Keyboard Hotplug
Linux Script Extract Information from Excel to Create Users
Symbolic Link to a Hook in Git
JSON Command Line Formatter Tool for Linux
Are Tar.Gz and Tgz the Same Thing
When Grep "\\" Xxfile I Got "Trailing Backslash"
Given Two Directory Trees How to Find Which Files Are the Same