remove dots from value
up vote
0
down vote
favorite
I am trying to write a script that shows me if a service is running or not.
command:service ntpd status | awk '{print $5}'
output:running...
how can i remove those dots? or is there a better way to find out that a service is running or not?
shell-script centos awk services
add a comment |
up vote
0
down vote
favorite
I am trying to write a script that shows me if a service is running or not.
command:service ntpd status | awk '{print $5}'
output:running...
how can i remove those dots? or is there a better way to find out that a service is running or not?
shell-script centos awk services
You could usesed
to remove the dots. However,service name status
is a script that tells you if a service is running or not. Not sure why you would need something else.
– Peschke
Dec 2 at 5:42
What do the dots matter? That command gives you want you want which is the status of the service.
– Nasir Riley
Dec 2 at 5:57
its going to be shown in a monitoring program. i don`t know how to do that with sed. i never used sed befor.
– BlackCrystal
Dec 2 at 6:00
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to write a script that shows me if a service is running or not.
command:service ntpd status | awk '{print $5}'
output:running...
how can i remove those dots? or is there a better way to find out that a service is running or not?
shell-script centos awk services
I am trying to write a script that shows me if a service is running or not.
command:service ntpd status | awk '{print $5}'
output:running...
how can i remove those dots? or is there a better way to find out that a service is running or not?
shell-script centos awk services
shell-script centos awk services
asked Dec 2 at 5:26
BlackCrystal
16711
16711
You could usesed
to remove the dots. However,service name status
is a script that tells you if a service is running or not. Not sure why you would need something else.
– Peschke
Dec 2 at 5:42
What do the dots matter? That command gives you want you want which is the status of the service.
– Nasir Riley
Dec 2 at 5:57
its going to be shown in a monitoring program. i don`t know how to do that with sed. i never used sed befor.
– BlackCrystal
Dec 2 at 6:00
add a comment |
You could usesed
to remove the dots. However,service name status
is a script that tells you if a service is running or not. Not sure why you would need something else.
– Peschke
Dec 2 at 5:42
What do the dots matter? That command gives you want you want which is the status of the service.
– Nasir Riley
Dec 2 at 5:57
its going to be shown in a monitoring program. i don`t know how to do that with sed. i never used sed befor.
– BlackCrystal
Dec 2 at 6:00
You could use
sed
to remove the dots. However, service name status
is a script that tells you if a service is running or not. Not sure why you would need something else.– Peschke
Dec 2 at 5:42
You could use
sed
to remove the dots. However, service name status
is a script that tells you if a service is running or not. Not sure why you would need something else.– Peschke
Dec 2 at 5:42
What do the dots matter? That command gives you want you want which is the status of the service.
– Nasir Riley
Dec 2 at 5:57
What do the dots matter? That command gives you want you want which is the status of the service.
– Nasir Riley
Dec 2 at 5:57
its going to be shown in a monitoring program. i don`t know how to do that with sed. i never used sed befor.
– BlackCrystal
Dec 2 at 6:00
its going to be shown in a monitoring program. i don`t know how to do that with sed. i never used sed befor.
– BlackCrystal
Dec 2 at 6:00
add a comment |
3 Answers
3
active
oldest
votes
up vote
3
down vote
accepted
You could use the awk's gsub
command:
$ service ntpd status | awk '{gsub(/[.]/,"");print $NF}'
running
Using NF
since the status word is usually the last word of the output.
The command service
is the old way to check services (for systems not using systemctl yet). With systemd use:
systemctl is-active sshd >/dev/null 2>&1 && echo YES || echo NO
add a comment |
up vote
1
down vote
I tried with below sed command and it worked fine
@praveen_linux_example ~]# service sshd status| sed "s/.//g"
openssh-daemon (pid 2268) is running
add a comment |
up vote
1
down vote
If you insist on sed
:
service ntpd status | sed 's/^.* |.*$//g'
running
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
You could use the awk's gsub
command:
$ service ntpd status | awk '{gsub(/[.]/,"");print $NF}'
running
Using NF
since the status word is usually the last word of the output.
The command service
is the old way to check services (for systems not using systemctl yet). With systemd use:
systemctl is-active sshd >/dev/null 2>&1 && echo YES || echo NO
add a comment |
up vote
3
down vote
accepted
You could use the awk's gsub
command:
$ service ntpd status | awk '{gsub(/[.]/,"");print $NF}'
running
Using NF
since the status word is usually the last word of the output.
The command service
is the old way to check services (for systems not using systemctl yet). With systemd use:
systemctl is-active sshd >/dev/null 2>&1 && echo YES || echo NO
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
You could use the awk's gsub
command:
$ service ntpd status | awk '{gsub(/[.]/,"");print $NF}'
running
Using NF
since the status word is usually the last word of the output.
The command service
is the old way to check services (for systems not using systemctl yet). With systemd use:
systemctl is-active sshd >/dev/null 2>&1 && echo YES || echo NO
You could use the awk's gsub
command:
$ service ntpd status | awk '{gsub(/[.]/,"");print $NF}'
running
Using NF
since the status word is usually the last word of the output.
The command service
is the old way to check services (for systems not using systemctl yet). With systemd use:
systemctl is-active sshd >/dev/null 2>&1 && echo YES || echo NO
answered Dec 2 at 6:21
Isaac
10.3k11446
10.3k11446
add a comment |
add a comment |
up vote
1
down vote
I tried with below sed command and it worked fine
@praveen_linux_example ~]# service sshd status| sed "s/.//g"
openssh-daemon (pid 2268) is running
add a comment |
up vote
1
down vote
I tried with below sed command and it worked fine
@praveen_linux_example ~]# service sshd status| sed "s/.//g"
openssh-daemon (pid 2268) is running
add a comment |
up vote
1
down vote
up vote
1
down vote
I tried with below sed command and it worked fine
@praveen_linux_example ~]# service sshd status| sed "s/.//g"
openssh-daemon (pid 2268) is running
I tried with below sed command and it worked fine
@praveen_linux_example ~]# service sshd status| sed "s/.//g"
openssh-daemon (pid 2268) is running
answered Dec 2 at 6:22
Praveen Kumar BS
1,166138
1,166138
add a comment |
add a comment |
up vote
1
down vote
If you insist on sed
:
service ntpd status | sed 's/^.* |.*$//g'
running
add a comment |
up vote
1
down vote
If you insist on sed
:
service ntpd status | sed 's/^.* |.*$//g'
running
add a comment |
up vote
1
down vote
up vote
1
down vote
If you insist on sed
:
service ntpd status | sed 's/^.* |.*$//g'
running
If you insist on sed
:
service ntpd status | sed 's/^.* |.*$//g'
running
answered Dec 2 at 13:10
RudiC
3,6721312
3,6721312
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f485439%2fremove-dots-from-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You could use
sed
to remove the dots. However,service name status
is a script that tells you if a service is running or not. Not sure why you would need something else.– Peschke
Dec 2 at 5:42
What do the dots matter? That command gives you want you want which is the status of the service.
– Nasir Riley
Dec 2 at 5:57
its going to be shown in a monitoring program. i don`t know how to do that with sed. i never used sed befor.
– BlackCrystal
Dec 2 at 6:00