Quale systemctlopzione o comando dovrei usare per visualizzare un riepilogo di tutti i servizi attualmente in esecuzione?
Quale systemctlopzione o comando dovrei usare per visualizzare un riepilogo di tutti i servizi attualmente in esecuzione?
Risposte:
È possibile utilizzare alcune delle systemctlopzioni:
-t, --type=
The argument should be a comma-separated list of unit types such as
service and socket.
If one of the arguments is a unit type, when listing units, limit
display to certain unit types. Otherwise, units of all types will
be shown.
As a special case, if one of the arguments is help, a list of
allowed values will be printed and the program will exit.
--state=
The argument should be a comma-separated list of unit LOAD, SUB, or
ACTIVE states. When listing units, show only those in the specified
states. Use --state=failed to show only failed units.
As a special case, if one of the arguments is help, a list of
allowed values will be printed and the program will exit.
Quindi probabilmente vuoi:
systemctl --type=service --state=active list-units
Che elenca tutti i servizi attivi inclusi quelli che sono usciti. Se stai solo cercando quelli in esecuzione in questo momento puoi usare:
systemctl --type=service --state=running list-units
systemctlcomando senza alcun sottocomando presuppone list-units, quindi ... systemctl --type-service --state=running, o semplicemente un semplice systemctlper un rapido utilizzo.
Lo è (vedi man 1 systemctl ):
systemctl list-units | grep -E 'service.*running'
o (vedi anche man 8 service )
service --status-all
Dove [+]indica servizi che sono effettivamente in esecuzione.
Dopo essermi guardato intorno più a lungo del necessario, mi sono inventato questo metodo leggermente diverso per determinare i servizi in esecuzione. Mostra anche come contare il numero di servizi in esecuzione. In questo modo si garantisce che non si verifichi accidentalmente qualcosa con la parola running o service nel nome stesso dei servizi.
# Output all active services:
systemctl -t service --state=active --no-pager --no-legend
# Count of all active services:
systemctl -t service --state=active --no-pager --no-legend | grep -c -
# Output all running services:
systemctl -t service --state=active --no-pager --no-legend | egrep '^*\.service.*running'
# Count of all running services:
systemctl -t service --state=active --no-pager --no-legend | egrep '^*\.service.*running' -c -
# Output only the service and its description:
systemctl -t service --state=active --no-pager --no-legend | egrep '^*\.service.*running' | awk 'BEGIN { FS = " ";} {for (i = 2; i <= 4; i++) { $i = "" }; print}'