How do I get just status of the apachectl
status command?
For example, in the output below, I just want to take the word “running”
Active: active (running) since Thu 2019-12-05 08:23:56 -03; 22min ago
I managed to get uptime with the command:
apachectl status | sed -n '/ ago $ / p' | sed 's /. {62 } //'
However, I couldn’t adapt this command to just get the status.
3
Answers
You should actually do this in this fashion.
is-active
is the accurate command to get the status of systemctl services.OR more clearly:
OR as per Ed sir’s comment more safer option will be using usual
if
andelse
option as follows.From man page of systemctl:
Using
echo '...'
instead ofapachectl status
which I don’t have:That sed commands pipeline in your question has syntax errors and when I try to fix them I just get the output
min ago
:so idk if this is the output you want from that or not but consider:
I also have chicken.
If
apachectl status
producesActive: active (running) since Thu 2019-12-05 08:23:56 -03; 22min ago
your problem – getting the string between the first parentheses – can be solved asProof:
Pattern matches:
-n ... p
prints the result.