Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting systemctl service status

I am trying to get the status of systemctl service using below command.

systemctl --no-pager status service_name | grep "Active" | cut -d ":" -f2

The output i am getting is

active (exited) since Mon 2023-09-04 21

I just want active or inactive in the output. How do I achieve this ?

like image 526
PTK Avatar asked Dec 06 '25 07:12

PTK


1 Answers

systemctl is-active service_name

What this command does is check whether any of the specified units are active (i.e. running). Returns an exit code 0 if at least one is active, or non-zero otherwise. You can find it int the man manual

like image 133
lqinggang Avatar answered Dec 08 '25 19:12

lqinggang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!