-
Linux crontab을 이용하여 주기적으로 ping testLinux 2020. 5. 20. 10:10
[목표]
특정 ip에 ping을 날리는 sh 스크립트를 crontab에 등록하여 주기적으로 실행합니다.
[작업순서]
1. EC2 t3.nano 생성
2. Linux의 시간대를 한국으로 변경 - A 방법
sudo timedatectl set-timezone Asia/Seoul
2. Linux의 시간대를 한국으로 변경 - B 방법
sudo vi /etc/sysconfig/clock # ZONE="Asia/Seoul" 로 변경
sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime #시간대 정보를 Asia/Seoul로 참조
sudo reboot #시스템을 재부팅하여 모든 서비스 및 응용 프로그램에서 새 표준 시간대 정보를 적용
3. Timezone 변경여부 확인
date
4. ping 디렉토리 생성
mkdir ping
5. ping.sh 스트립트 작성
vi ping.sh
----------------------------
#! /bin/bash
# ping test
IP='(your target IP)'
LogFile='(your log file path)'
exec > $LogFile
date
ping -c 5 $IP
----------------------------
- 스크립트가 실행된 날짜와 시간, 특정 ip로 ping을 날리는 작업을 5번 반복
- 해당 작업내역을 log 파일에 저장 (exec >> 는 누적, exec >는 갱신)
6. sh 스크립트의 권한 변경
chmod 755 ping.sh
7. 스크립트 실행으로 정상여부 확인 (정상인경우 로그 파일 생성)
./ping.sh
8. crontab -e 에 ping.sh 추가 (기본 1분단위)
crontab -e
----------------------------
* * * * * /home/ec2-user/ping/ping.sh
----------------------------
9. crontab 정상여부 확인 (1분 단위로 로그갱신)
10. crontab -e 의 ping.sh를 10분 단위로 변경
crontab -e
----------------------------
*/10 * * * * /home/ec2-user/ping/ping.sh
----------------------------
끝.
!계정에 따라 별도의 crontab이 적용됩니다!
[참고]
(shell 스크립트의 기본)
linuxcommand.org/lc3_wss0010.php
Writing shell scripts - Lesson 1: Writing your first script and getting it to work
© 2000-2020, William E. Shotts, Jr. Verbatim copying and distribution of this entire article is permitted in any medium, provided this copyright notice is preserved. Linux® is a registered trademark of Linus Torvalds.
linuxcommand.org
(ping test)
The Linux Ping Command
Ping or Packet Internet Groper is a network administration utility used to check the connectivity status between a source and a destination computer/device over an IP network. It also helps you assess the time it takes to send and receive
vitux.com
(로그파일 txt에 올리기)
stackoverflow.com/questions/25833676/redirect-echo-output-in-shell-script-to-logfile
Redirect echo output in shell script to logfile
I have a shell script with lots of echo in it. I would like to redirect the output to a logfile. I know there is the command call cmd > logfile.txt, or to do it in the file echo 'xy' > logfil...
stackoverflow.com
(Linux crontab)
리눅스 크론탭(Linux Crontab) 사용법 :: JDM's Blog
* 이 포스팅은 네이버 블로그에서 작성(2013.04.01)한 내용을 옮겨온 것입니다. 오늘은 리눅스 크론탭에 대해 알아볼까 합니다. 음, 윈도우에서는 스케줄러와 비슷하다고 보면 되겠네요. "특정 시간
jdm.kr
'Linux' 카테고리의 다른 글
Linux crontab 백업, 비우기, 복원하기 (0) 2020.07.16 Linux, vmstat과 crontab을 이용한 사용량 로그 저장하기 (2) 2020.05.27 Amazon Linux에서 시간대 변경 (0) 2020.05.11 dd 명령어를 이용한 Linux 더미 파일 생성 (0) 2020.04.21 Putty를 이용한 Linux SSH 원격접속 (공개키 사용) (0) 2020.04.20