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?










share|improve this question






















  • 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

















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?










share|improve this question






















  • 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















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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 2 at 5:26









BlackCrystal

16711




16711












  • 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




















  • 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


















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












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





share|improve this answer




























    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





    share|improve this answer




























      up vote
      1
      down vote













      If you insist on sed:



      service ntpd status | sed 's/^.* |.*$//g'
      running





      share|improve this answer





















        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "106"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        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

























        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





        share|improve this answer

























          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





          share|improve this answer























            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





            share|improve this answer












            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






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Dec 2 at 6:21









            Isaac

            10.3k11446




            10.3k11446
























                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





                share|improve this answer

























                  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





                  share|improve this answer























                    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





                    share|improve this answer












                    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






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Dec 2 at 6:22









                    Praveen Kumar BS

                    1,166138




                    1,166138






















                        up vote
                        1
                        down vote













                        If you insist on sed:



                        service ntpd status | sed 's/^.* |.*$//g'
                        running





                        share|improve this answer

























                          up vote
                          1
                          down vote













                          If you insist on sed:



                          service ntpd status | sed 's/^.* |.*$//g'
                          running





                          share|improve this answer























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            If you insist on sed:



                            service ntpd status | sed 's/^.* |.*$//g'
                            running





                            share|improve this answer












                            If you insist on sed:



                            service ntpd status | sed 's/^.* |.*$//g'
                            running






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 2 at 13:10









                            RudiC

                            3,6721312




                            3,6721312






























                                draft saved

                                draft discarded




















































                                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.




                                draft saved


                                draft discarded














                                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





















































                                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







                                Popular posts from this blog

                                サソリ

                                広島県道265号伴広島線

                                Setup Asymptote in Texstudio