วันอาทิตย์ที่ 24 กรกฎาคม พ.ศ. 2559

ลง Customs Script บน UBNT Loco M5 เพื่อให้ต่อเน็ตอัตโนมัติเมื่อหลุด

บันทึกไว้อ่านวันหน้า เผื่อลืม
Script สำหรับให้ Loco M5 automatic renew DHCP อัตโนมัติเมื่อเน็ตหลุด (Ping หายนั่นแหล่ะ)

ขั้นตอน
1. SSH ไปที่ UBNT (ใช้ putty)
2. สร้างไฟล์ script.sh ขึ้นมา (ใน /var/etc/persistent)
3. ใส่ script เข้าไป
#!/bin/sh
while true; do 
/bin/sleep 15 #ระยะห่างในการ ping แต่ละครั้ง
if ping -c 1 -w 3 8.8.8.8 # -c คือจำนวนครั้งการ ping -w คือระยะเวลารอการตอบ ping
then
echo "Automatic WAN renew not needed"
continue 
else
/bin/kill -SIGUSR1 $(pidof udhcpc)
logger "Automatic WAN Renew"
fi
done
[ถ้าใช้ vi ก็ vi script.sh ; โค้ด ; esc,:w ; :q! ]
4. chmod +x script.sh
5. สร้างไฟล์ rc.postsysinit ขึ้นมา (ตรงนี้สามารถสร้างได้หลายแบบ ตามแต่งาน)
6. ใส่ code ลงไป
#!/bin/sh
/var/etc/persistent/script.sh &
7. chmod +x rc.postsysinit
8. พิมพ์ save เพื่อบันทึกลง flash memory
9. เสร็จ ลอง reboot ดูเพื่อให้ script ทำงาน
จะเห็นว่าในหน้า web ui จะมีคำว่า custom scripts: Enabled ปรากฏขึ้นมา
Loco M5 TrueWifi



Note: ถ้า /bin/kill -SIGUSR2 $(pidof udhcpc)จะเป็นการ Release DHCP จะไม่ต่อใหม่จนกว่าจะได้ /bin/kill -SIGUSR1 $(pidof udhcpc)

1 ความคิดเห็น: