Who rated this post

cancel
Showing results for 
Search instead for 
Did you mean: 
Bob_Zimmerman
Authority
Authority

'ntpq -p' shows the current status of ntpd, but it doesn't return a useful exit code when ntpd isn't running. The simplest way to check is probably to see if ntpd is running. 'ps -C ntpd' exits with code 0 if it finds at least one matching process, or code 1 if there aren't any matches.

[Expert@DallasSC]# clish -c "show ntp active"           
No
[Expert@DallasSC]# ntpq -p
ntpq: read: Connection refused
[Expert@DallasSC]# echo $?
0
[Expert@DallasSC]# ps -C ntpd
  PID TTY          TIME CMD
[Expert@DallasSC]# echo $?
1

[Expert@DallasticXL-s01-01:0]# clish -c "show ntp active"
Yes
[Expert@DallasticXL-s01-01:0]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*10.0.1.1        132.163.96.2     2 u  654 1024  377    0.966    0.517   0.830
[Expert@DallasticXL-s01-01:0]# echo $?
0
[Expert@DallasticXL-s01-01:0]# ps -C ntpd
  PID TTY          TIME CMD
18573 ?        00:00:00 ntpd
[Expert@DallasticXL-s01-01:0]# echo $?
0

 

View solution in original post

(1)
Who rated this post