/bin/sh: ntpq: command not found

Multi tool use
Multi tool use

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I've got this strange behaviour https://stackoverflow.com/q/46583758/2553194
but let me resume and refocus the problem:



I'm executing a java program launched using a shell script that goes like this:



#!/bin/bash
export PATH=.:$PATH

java -jar myJar.jar &


Inside my java code I execute this piped command



ntpq -c peers | awk ' $0 ~ /^*/ print $9'


in order to obtain the offset of the NTP synchronized server.



To execute a piped command inside a java program, I've to use the above mentioned line as an argument of /bin/sh. I execute /bin/sh not the piped command directly.



This is the equivalent that you can launch in a console [1]



/bin/sh -c 'ntpq -c peers | awk '"'"' $0 ~ /^*/ print $9'"'"''


Example output from ntpq



 remote refid st t when poll reach delay offset jitter
==============================================================================
*172.30.100.1 172.22.204.171 4 u 207 1024 377 1.490 53.388 49.372


Parsing it with awk, I obtain



53.388


Usually it goes well, but sometimes for reasons unknown [This is my question] my program stops working fine. It returns nothing when the execution of the piped command from the console returns a number.



Recovering the err from the executed process created by java, I've obtained this text




/bin/sh: ntpq: command not found




So, sometimes I can execute [1] from a java program and sometimes I can't. Something is happening in the SO behind the scene. Can someone enlighten me, please?







share|improve this question


















  • 1




    Have you tried to pass the full path to the ntpq binary? Does this cause issues?
    – Valentin B
    Oct 20 '17 at 10:04










  • @val0x00ff You mean executing /bin/sh -c '/usr/sbin/ntpq -c peers | awk '"'"' $0 ~ /^*/ print $9'"'"'' from my java code? I've just tried and it works. But my original solution works too until it doesn't. I don't know how to force the anomalous situation. How can I proof that yours is better? :-(
    – RubioRic
    Oct 20 '17 at 10:17










  • This could be caused by ntpq not always return the expected result. For example, I just ran ntpq -c peers and I get things like *46.243.26.34 (4 .GPS. 1 u 15 64 3 22.912 -1.441 4.577 As you can see column 9 isn't the offset anymore. Also are you exporting JAVA as well?
    – Valentin B
    Oct 20 '17 at 10:22










  • @val0x00ff So you have a different SO or a different ntpq implementation, haven´t you? Anyway, it doesn`t explain why sometimes my SO found ntpq command and sometimes doesn't. Thanx for your comments :-)
    – RubioRic
    Oct 20 '17 at 10:41














up vote
0
down vote

favorite












I've got this strange behaviour https://stackoverflow.com/q/46583758/2553194
but let me resume and refocus the problem:



I'm executing a java program launched using a shell script that goes like this:



#!/bin/bash
export PATH=.:$PATH

java -jar myJar.jar &


Inside my java code I execute this piped command



ntpq -c peers | awk ' $0 ~ /^*/ print $9'


in order to obtain the offset of the NTP synchronized server.



To execute a piped command inside a java program, I've to use the above mentioned line as an argument of /bin/sh. I execute /bin/sh not the piped command directly.



This is the equivalent that you can launch in a console [1]



/bin/sh -c 'ntpq -c peers | awk '"'"' $0 ~ /^*/ print $9'"'"''


Example output from ntpq



 remote refid st t when poll reach delay offset jitter
==============================================================================
*172.30.100.1 172.22.204.171 4 u 207 1024 377 1.490 53.388 49.372


Parsing it with awk, I obtain



53.388


Usually it goes well, but sometimes for reasons unknown [This is my question] my program stops working fine. It returns nothing when the execution of the piped command from the console returns a number.



Recovering the err from the executed process created by java, I've obtained this text




/bin/sh: ntpq: command not found




So, sometimes I can execute [1] from a java program and sometimes I can't. Something is happening in the SO behind the scene. Can someone enlighten me, please?







share|improve this question


















  • 1




    Have you tried to pass the full path to the ntpq binary? Does this cause issues?
    – Valentin B
    Oct 20 '17 at 10:04










  • @val0x00ff You mean executing /bin/sh -c '/usr/sbin/ntpq -c peers | awk '"'"' $0 ~ /^*/ print $9'"'"'' from my java code? I've just tried and it works. But my original solution works too until it doesn't. I don't know how to force the anomalous situation. How can I proof that yours is better? :-(
    – RubioRic
    Oct 20 '17 at 10:17










  • This could be caused by ntpq not always return the expected result. For example, I just ran ntpq -c peers and I get things like *46.243.26.34 (4 .GPS. 1 u 15 64 3 22.912 -1.441 4.577 As you can see column 9 isn't the offset anymore. Also are you exporting JAVA as well?
    – Valentin B
    Oct 20 '17 at 10:22










  • @val0x00ff So you have a different SO or a different ntpq implementation, haven´t you? Anyway, it doesn`t explain why sometimes my SO found ntpq command and sometimes doesn't. Thanx for your comments :-)
    – RubioRic
    Oct 20 '17 at 10:41












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I've got this strange behaviour https://stackoverflow.com/q/46583758/2553194
but let me resume and refocus the problem:



I'm executing a java program launched using a shell script that goes like this:



#!/bin/bash
export PATH=.:$PATH

java -jar myJar.jar &


Inside my java code I execute this piped command



ntpq -c peers | awk ' $0 ~ /^*/ print $9'


in order to obtain the offset of the NTP synchronized server.



To execute a piped command inside a java program, I've to use the above mentioned line as an argument of /bin/sh. I execute /bin/sh not the piped command directly.



This is the equivalent that you can launch in a console [1]



/bin/sh -c 'ntpq -c peers | awk '"'"' $0 ~ /^*/ print $9'"'"''


Example output from ntpq



 remote refid st t when poll reach delay offset jitter
==============================================================================
*172.30.100.1 172.22.204.171 4 u 207 1024 377 1.490 53.388 49.372


Parsing it with awk, I obtain



53.388


Usually it goes well, but sometimes for reasons unknown [This is my question] my program stops working fine. It returns nothing when the execution of the piped command from the console returns a number.



Recovering the err from the executed process created by java, I've obtained this text




/bin/sh: ntpq: command not found




So, sometimes I can execute [1] from a java program and sometimes I can't. Something is happening in the SO behind the scene. Can someone enlighten me, please?







share|improve this question














I've got this strange behaviour https://stackoverflow.com/q/46583758/2553194
but let me resume and refocus the problem:



I'm executing a java program launched using a shell script that goes like this:



#!/bin/bash
export PATH=.:$PATH

java -jar myJar.jar &


Inside my java code I execute this piped command



ntpq -c peers | awk ' $0 ~ /^*/ print $9'


in order to obtain the offset of the NTP synchronized server.



To execute a piped command inside a java program, I've to use the above mentioned line as an argument of /bin/sh. I execute /bin/sh not the piped command directly.



This is the equivalent that you can launch in a console [1]



/bin/sh -c 'ntpq -c peers | awk '"'"' $0 ~ /^*/ print $9'"'"''


Example output from ntpq



 remote refid st t when poll reach delay offset jitter
==============================================================================
*172.30.100.1 172.22.204.171 4 u 207 1024 377 1.490 53.388 49.372


Parsing it with awk, I obtain



53.388


Usually it goes well, but sometimes for reasons unknown [This is my question] my program stops working fine. It returns nothing when the execution of the piped command from the console returns a number.



Recovering the err from the executed process created by java, I've obtained this text




/bin/sh: ntpq: command not found




So, sometimes I can execute [1] from a java program and sometimes I can't. Something is happening in the SO behind the scene. Can someone enlighten me, please?









share|improve this question













share|improve this question




share|improve this question








edited Oct 26 '17 at 10:15

























asked Oct 20 '17 at 9:42









RubioRic

1217




1217







  • 1




    Have you tried to pass the full path to the ntpq binary? Does this cause issues?
    – Valentin B
    Oct 20 '17 at 10:04










  • @val0x00ff You mean executing /bin/sh -c '/usr/sbin/ntpq -c peers | awk '"'"' $0 ~ /^*/ print $9'"'"'' from my java code? I've just tried and it works. But my original solution works too until it doesn't. I don't know how to force the anomalous situation. How can I proof that yours is better? :-(
    – RubioRic
    Oct 20 '17 at 10:17










  • This could be caused by ntpq not always return the expected result. For example, I just ran ntpq -c peers and I get things like *46.243.26.34 (4 .GPS. 1 u 15 64 3 22.912 -1.441 4.577 As you can see column 9 isn't the offset anymore. Also are you exporting JAVA as well?
    – Valentin B
    Oct 20 '17 at 10:22










  • @val0x00ff So you have a different SO or a different ntpq implementation, haven´t you? Anyway, it doesn`t explain why sometimes my SO found ntpq command and sometimes doesn't. Thanx for your comments :-)
    – RubioRic
    Oct 20 '17 at 10:41












  • 1




    Have you tried to pass the full path to the ntpq binary? Does this cause issues?
    – Valentin B
    Oct 20 '17 at 10:04










  • @val0x00ff You mean executing /bin/sh -c '/usr/sbin/ntpq -c peers | awk '"'"' $0 ~ /^*/ print $9'"'"'' from my java code? I've just tried and it works. But my original solution works too until it doesn't. I don't know how to force the anomalous situation. How can I proof that yours is better? :-(
    – RubioRic
    Oct 20 '17 at 10:17










  • This could be caused by ntpq not always return the expected result. For example, I just ran ntpq -c peers and I get things like *46.243.26.34 (4 .GPS. 1 u 15 64 3 22.912 -1.441 4.577 As you can see column 9 isn't the offset anymore. Also are you exporting JAVA as well?
    – Valentin B
    Oct 20 '17 at 10:22










  • @val0x00ff So you have a different SO or a different ntpq implementation, haven´t you? Anyway, it doesn`t explain why sometimes my SO found ntpq command and sometimes doesn't. Thanx for your comments :-)
    – RubioRic
    Oct 20 '17 at 10:41







1




1




Have you tried to pass the full path to the ntpq binary? Does this cause issues?
– Valentin B
Oct 20 '17 at 10:04




Have you tried to pass the full path to the ntpq binary? Does this cause issues?
– Valentin B
Oct 20 '17 at 10:04












@val0x00ff You mean executing /bin/sh -c '/usr/sbin/ntpq -c peers | awk '"'"' $0 ~ /^*/ print $9'"'"'' from my java code? I've just tried and it works. But my original solution works too until it doesn't. I don't know how to force the anomalous situation. How can I proof that yours is better? :-(
– RubioRic
Oct 20 '17 at 10:17




@val0x00ff You mean executing /bin/sh -c '/usr/sbin/ntpq -c peers | awk '"'"' $0 ~ /^*/ print $9'"'"'' from my java code? I've just tried and it works. But my original solution works too until it doesn't. I don't know how to force the anomalous situation. How can I proof that yours is better? :-(
– RubioRic
Oct 20 '17 at 10:17












This could be caused by ntpq not always return the expected result. For example, I just ran ntpq -c peers and I get things like *46.243.26.34 (4 .GPS. 1 u 15 64 3 22.912 -1.441 4.577 As you can see column 9 isn't the offset anymore. Also are you exporting JAVA as well?
– Valentin B
Oct 20 '17 at 10:22




This could be caused by ntpq not always return the expected result. For example, I just ran ntpq -c peers and I get things like *46.243.26.34 (4 .GPS. 1 u 15 64 3 22.912 -1.441 4.577 As you can see column 9 isn't the offset anymore. Also are you exporting JAVA as well?
– Valentin B
Oct 20 '17 at 10:22












@val0x00ff So you have a different SO or a different ntpq implementation, haven´t you? Anyway, it doesn`t explain why sometimes my SO found ntpq command and sometimes doesn't. Thanx for your comments :-)
– RubioRic
Oct 20 '17 at 10:41




@val0x00ff So you have a different SO or a different ntpq implementation, haven´t you? Anyway, it doesn`t explain why sometimes my SO found ntpq command and sometimes doesn't. Thanx for your comments :-)
– RubioRic
Oct 20 '17 at 10:41










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










I originally posted a similar question in StackOverflow, thinking that the problem may be related with the java programming but it wasn't.



Finally we found what was happening.



My java program is launched with a shell script. When we execute the script manually, ntpq command is found and invoked successfully. The problem arises when the software is fully deployed. In the final environment we've got a cron scheduled demon that keeps our program alive but PATH established by cron is different from the PATH that our profile has got assigned.



PATH used by cron:



.:/usr/bin:/bin


PATH that we got login for launching the script manually:



/usr/sbin:/usr/bin:/bin:/sbin:/usr/lib:/usr/lib64:/local/users/nor:
/usr/local/bin:/usr/local/lib:.


Usually ntpq is in



/usr/sbin/ntpq


Here you can find a better description of the problem and various solutions.






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: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    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%2f399315%2fbin-sh-ntpq-command-not-found%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    I originally posted a similar question in StackOverflow, thinking that the problem may be related with the java programming but it wasn't.



    Finally we found what was happening.



    My java program is launched with a shell script. When we execute the script manually, ntpq command is found and invoked successfully. The problem arises when the software is fully deployed. In the final environment we've got a cron scheduled demon that keeps our program alive but PATH established by cron is different from the PATH that our profile has got assigned.



    PATH used by cron:



    .:/usr/bin:/bin


    PATH that we got login for launching the script manually:



    /usr/sbin:/usr/bin:/bin:/sbin:/usr/lib:/usr/lib64:/local/users/nor:
    /usr/local/bin:/usr/local/lib:.


    Usually ntpq is in



    /usr/sbin/ntpq


    Here you can find a better description of the problem and various solutions.






    share|improve this answer


























      up vote
      2
      down vote



      accepted










      I originally posted a similar question in StackOverflow, thinking that the problem may be related with the java programming but it wasn't.



      Finally we found what was happening.



      My java program is launched with a shell script. When we execute the script manually, ntpq command is found and invoked successfully. The problem arises when the software is fully deployed. In the final environment we've got a cron scheduled demon that keeps our program alive but PATH established by cron is different from the PATH that our profile has got assigned.



      PATH used by cron:



      .:/usr/bin:/bin


      PATH that we got login for launching the script manually:



      /usr/sbin:/usr/bin:/bin:/sbin:/usr/lib:/usr/lib64:/local/users/nor:
      /usr/local/bin:/usr/local/lib:.


      Usually ntpq is in



      /usr/sbin/ntpq


      Here you can find a better description of the problem and various solutions.






      share|improve this answer
























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        I originally posted a similar question in StackOverflow, thinking that the problem may be related with the java programming but it wasn't.



        Finally we found what was happening.



        My java program is launched with a shell script. When we execute the script manually, ntpq command is found and invoked successfully. The problem arises when the software is fully deployed. In the final environment we've got a cron scheduled demon that keeps our program alive but PATH established by cron is different from the PATH that our profile has got assigned.



        PATH used by cron:



        .:/usr/bin:/bin


        PATH that we got login for launching the script manually:



        /usr/sbin:/usr/bin:/bin:/sbin:/usr/lib:/usr/lib64:/local/users/nor:
        /usr/local/bin:/usr/local/lib:.


        Usually ntpq is in



        /usr/sbin/ntpq


        Here you can find a better description of the problem and various solutions.






        share|improve this answer














        I originally posted a similar question in StackOverflow, thinking that the problem may be related with the java programming but it wasn't.



        Finally we found what was happening.



        My java program is launched with a shell script. When we execute the script manually, ntpq command is found and invoked successfully. The problem arises when the software is fully deployed. In the final environment we've got a cron scheduled demon that keeps our program alive but PATH established by cron is different from the PATH that our profile has got assigned.



        PATH used by cron:



        .:/usr/bin:/bin


        PATH that we got login for launching the script manually:



        /usr/sbin:/usr/bin:/bin:/sbin:/usr/lib:/usr/lib64:/local/users/nor:
        /usr/local/bin:/usr/local/lib:.


        Usually ntpq is in



        /usr/sbin/ntpq


        Here you can find a better description of the problem and various solutions.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 26 '17 at 9:52

























        answered Oct 26 '17 at 9:15









        RubioRic

        1217




        1217



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399315%2fbin-sh-ntpq-command-not-found%23new-answer', 'question_page');

            );

            Post as a guest













































































            9jtYpV
            Ecnx evAVbVpgt nDkxeov hk OmucNMoV,0oJ,IHThCCLwZU,2,F 5TqRnyHYJ IaIjM52p3ud3vm3gl1EDf,XQ97LrJtPRU

            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            How many registers does an x86_64 CPU actually have?

            Displaying single band from multi-band raster using QGIS