Archive/기타
crontab curl http_status telegram
은풍
2020. 9. 3. 17:11
A. 텔레그램 봇 만들기
참조링크 : m.blog.naver.com/hosang46/221027388748
텔레그램 봇을 사용하여 SMS (Push) 기능 대체하기
요즘, 집에서 구동하는 개인용 NAS가 많이 보편화되었다. 모니터가 따로 없고, 상시 구동되는 NAS의 ...
blog.naver.com
1. 텔레그램 앱에서 @BotFather 대화창 시작
2. /newbot
3. 봇 이름 생성
4. 봇 토큰 기록
5. 만든 봇과 채팅방 개설
6. https://api.telegram.org/bot[토큰]/getUpdates
7. https://api.telegram.org/bot[토큰]/sendMessage?chat_id=[내chat_id]&text=[메세지]
B. curl 이용 웹사이트의 http status 코드를 받아 200 이 아닌 경우 텔레그램으로 메시지 보내기 shell
#!/bin/bash
STATUS=$(curl -s -o /dev/null -w '%{http_code}' https://example.com)
TIMESTRING=$(date +"%Y%m%d_%H%M%S")
if [ $STATUS -ne 200 ]; then
curl -d "chat_id=[내 CHAT ID]&text=$TIMESTRING%20[메시지]" \
-H "Content-Type: application/x-www-form-urlencoded" \
-X GET https://api.telegram.org/bot[토큰]/sendMessage
fi
C. crontab 으로 10분마다 체크
10 * * * * [쉘 파일경로]/[쉘 파일명]
반응형