Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Danny
Champion Champion
Champion
Jump to solution

Verify if NTP is enabled in expert mode?

In Gaia expert mode, is it possible to check if NTP is enabled without running clish -c "show ntp active"?
This is to avoid any possible config lock errors. I'd prefer something like a quick grep check, if possible.

Current command:
[Expert@firewall:0]# clish -c "show ntp active"
Output:
CLINFR0771 Config lock is owned by admin. Use the command 'lock database override' to acquire the lock.
1_01:
No

0 Kudos
1 Solution

Accepted Solutions
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)
3 Replies
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

 

(1)
Danny
Champion Champion
Champion

Thanks for your efforts.
After some additional checks on my side, I'm going with pidof ntpd &>/dev/null; echo $?

0 Kudos
the_rock
Legend
Legend

Just tried it in R81.20 and R82, worked fine.

Andy

[Expert@CP-GW:0]# clish -c "show ntp active"
No
[Expert@CP-GW:0]#

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events