나는 라스베가스 파이가 있습니다. 시간이 ntpd와 동기화되면 바로 스크립트를 실행하고 싶습니다. 스크립트에 올바른 datetime이 필요합니다. 내가 어떻게 할 수 있니?ntpd 동기화 후 스크립트 실행
3
A
답변
1
ntpdate를 호출 할 수있는 권한이있는 사용자 (시스템의 시간을 조정할 수있는 사용자)가 있다고 가정 할 때 다음 스크립트를 사용할 수 있습니다. 예를 들어 ntp 서버 "0.ca를 사용하고 있습니다. pool.ntp.org "
#!/bin/bash
NEEDS_SYNC=1
while [ "$NEEDS_SYNC" -ne "0" ]; do
ntpdate -t 4 0.ca.pool.ntp.org
NEEDS_SYNC=$? # If this variable is set ot 0, time sync worked
sleep 2
done
# RUN THE SCRIPT THT NEEDS ntp SYNC'D TIME HERE
이 기능을 사용하려면 'ntpdate'패키지를 설치해야 할 수도 있습니다.
3
올바른 방법은 ntp-wait
을 사용하는 것입니다. ntp-wait
은 이러한 유형의 상황에 맞게 조정되었습니다. 다음은 매뉴얼 페이지입니다 :
ntp-wait(1) User Commands ntp-wait(1)
NAME
ntp-wait - Wait for ntpd to stabilize the system clock
SYNOPSIS
ntp-wait [-flag [value]]... [--opt-name [[=| ]value]]...
All arguments must be options.
DESCRIPTION
will send at most num-tries queries to sleeping for secs-between-
tries after each status return that says has not yet produced a syn‐
chronized and stable system clock.
will do this quietly, unless the v flag is provided.
OPTIONS
-n num-tries, --=num-tries
Number of times to check ntpd. This option takes an integer
number as its argument. The default num-tries for this option
is:
100
The maximum number of times we will check ntpd to see if it
has been able to synchronize and stabilize the system clock.
-s secs-between-tries, --=secs-between-tries
How long to sleep between tries. This option takes an integer
number as its argument. The default secs-between-tries for
this option is:
6
We will sleep for @file{secs-between-tries} after each query
of ntpd that returns "the time is not yet stable".
-v, -- Be verbose.
By default, ntp-wait is silent. With this option, ntp-wait
will provide status information.
-?, --help
Display usage information and exit.
-!, --more-help
Pass the extended usage information through a pager.
- [{v|c|n}], --version[={v|c|n}]
Output version of program and exit. The default mode is `v',
a simple version. The `c' mode will print copyright informa‐
tion and `n' will print the full copyright notice.
EXIT STATUS
One of the following exit values will be returned:
0 Successful program execution.
1 The operation failed or the command syntax was not valid.
+0
만약 ntp-wait가 -n 0 (영원히 기다림)과 같은 옵션을 가지고 있다면 ntp-wait를 더 좋아할 것입니다. 현재 옵션으로는 (내 인생의 추정 나머지와 같이) 매우 큰 숫자를 써야하고 코드를 읽는 다른 누군가는 큰 숫자와 초를 계산 * 아무 의미가 없다는 것을 인정하려고 ... 나는 양복이 맞지 않는다는 것을 재단사에게 불평 할 것이다. :) – davidovv
관련 문제
- 1. 현재 스크립트 실행 후
- 2. 자바 스크립트 탭 간 코드 실행 동기화
- 3. 백본 동기화 후 뷰 변경 실행 취소
- 4. 면도기 구문이 실행 된 후 스크립트 실행
- 5. 자바 스크립트 실행 후 실행 취소
- 6. 설치 후 izpack에 설치 후 스크립트 실행
- 7. 사용자 로그인 후 스크립트 실행
- 8. 양식 제출 후 스크립트 실행
- 9. Jquery 완료 후 스크립트 실행
- 10. Maven 설치 후 스크립트 실행
- 11. 브런치에서 빌드 후 스크립트 실행
- 12. 스크립트 실행 후 AppleScript 종료
- 13. "ntpd -c 피어"의 출력에서 '로컬'열 이해
- 14. 자바 스크립트 시간 동기화
- 15. 데이터베이스 정리 후 동기화
- 16. 동기화 장기 실행 작업
- 17. 배너 실행 동기화
- 18. 실행 방법 동기화 vbscript
- 19. XML 애니메이션 동기화 실행
- 20. 스크립트 실행 후 맨 위로 돌아 가기
- 21. 스크립트 실행 후 PowerShell 프로세스 종료
- 22. asp.net VB 스크립트 실행 후 페이지가 닫힙니다
- 23. 서버 측 스크립트 실행 후 탭 닫기
- 24. 페이지가로드 된 후 자바 스크립트 실행
- 25. 페이지로드 후 스크립트 추가 및 실행
- 26. HTTPBuilder 자바 스크립트 실행 후 가져 오기
- 27. Joomla : 사용자 로그인 후 자바 스크립트 실행
- 28. 모든 git 푸시 후 스크립트 실행
- 29. dom 준비 후 자바 스크립트 실행
- 30. Ruby : 스크립트 실행 후 콘솔 열기
나는 $을 이해하지 못합니까? $는 무엇입니까? – davidovv
죄송합니다. $을 (를) 검색하기가 어려웠습니까? 구글에서,하지만 마침내 알아 냈어, $? 명령 종료 상태입니다. – davidovv
질문을 보았습니다. 죄송합니다. 나는 당신이 그것을 알아 낸 것을 기뻐합니다. 맞았 어, $? ntpdate의 종료 상태를 유지합니다. ntpdate는 날짜가 효과적으로 설정 될 때만 0을 반환합니다. –