ส่งการแจ้งเตือนเมื่อ Plot Chia ใน VPS เสร็จเข้าไลน์ Notify

line notify

สำหรับบทความในตอนนี้จะไม่ได้อธิบายขั้นตอนการทำนะครับ แต่จะอธิบายการทำงานของ shell script ที่เขียนขึ้นมา เพื่อให้ส่งการแจ้งเตือนเมื่อไฟล์ที่พลอตสำเร็จแล้ว มาที่ Line Notify ของเรา

เริ่มแรกเราต้องสร้าง script ขึ้นมาก่อน สมมุติว่าชื่อ endplot.sh

#!/bin/bash
   if  find -iname "*.plot" -type f -mtime -0.02 | grep  k32
then
   curl -X POST -H 'Authorization: Bearer Line notify token' -F 'message=VDS พลอตไฟล์สำเร็จ! มีไฟล์ Plot อยู่ใน /plots-final ดาวน์โหลดเสร็จแล้วต้องลบด้วยนะ' 'https://notify-api.line.me/api/notify'
fi

อธิบายสคริป เป็นการใช้คำสั่ง find ในการค้นหาไฟล์ ที่นามสกุลไฟล์ .plot และชื่อไฟล์มีคำว่า K32 อยู่ด้วย ใช้ -mtime ในการตรวจสอบเวลาของไฟล์ที่สร้างขึ้นมาว่าสร้างเสร็จมาแล้วกี่ชั่วโมง จากสคริปนี้ใช้ -mtime -0.02 คือไฟล์ที่สร้างเสร็จมาแล้ว 0.02 ชั่วโมง หรือ 1 นาทีกว่า เมื่อเจอไฟล์ที่ต้องการแล้วให้ส่งการแจ้งตือนมาที่ line notify โดยใช้ curl

กรณีที่ไฟล์ที่สร้างมาแล้ว เกิน 0.02 ชั่วโมงจะไม่ส่งการแจ้งเตือน

การใช้งานก็แค่ตั้ง crontab ให้รันสคริปเช็คทุกๆ 2 นาที หรือแล้วแต่จะต้องการ

*/1 * * * * /root/endplot.sh
Div24Hr.COM
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.