/bin/sh: ntpq: command not found
Clash 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?
bash shell process cron ntp
add a comment |Â
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?
bash shell process cron ntp
1
Have you tried to pass the full path to thentpq
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 byntpq
not always return the expected result. For example, I just ranntpq -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 seecolumn 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
add a comment |Â
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?
bash shell process cron ntp
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?
bash shell process cron ntp
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 thentpq
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 byntpq
not always return the expected result. For example, I just ranntpq -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 seecolumn 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
add a comment |Â
1
Have you tried to pass the full path to thentpq
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 byntpq
not always return the expected result. For example, I just ranntpq -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 seecolumn 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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited Oct 26 '17 at 9:52
answered Oct 26 '17 at 9:15
RubioRic
1217
1217
add a comment |Â
add a comment |Â
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
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
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
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
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
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 ranntpq -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 seecolumn 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