<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Just My Life &#187; sms</title>
	<atom:link href="http://imrgill.com/tag/sms/feed/" rel="self" type="application/rss+xml" />
	<link>http://imrgill.com</link>
	<description>I&#039;m mrGilL, I&#039;m Newbie Admin</description>
	<lastBuildDate>Thu, 02 Sep 2010 08:25:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Shell Script แจ้งเตือน SMS เมื่อ Hard Disk ใกล้เต็มแบบฟรีๆ</title>
		<link>http://imrgill.com/2009/12/13/shell-script-alert-sms-when-disk-small-left.html</link>
		<comments>http://imrgill.com/2009/12/13/shell-script-alert-sms-when-disk-small-left.html#comments</comments>
		<pubDate>Sat, 12 Dec 2009 21:29:19 +0000</pubDate>
		<dc:creator>mrgill</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[google calendar]]></category>
		<category><![CDATA[hard disk]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[sms]]></category>

		<guid isPermaLink="false">http://imrgill.com/?p=473</guid>
		<description><![CDATA[สวัสดีครับต่อยอดจากเรื่อง Server Down รู้ได้ทันทีผ่าน SMS แถมฟรี ที่เขียนไว้วันก่อน วันนี้เอามาประยุกต์ให้ script เช็คสถานะของ hard disk ครับโดยให้ส่ง sms เตือนเมื่อมีการใช้งาน partition ใดๆ เกิน 90% มาดูตัว code ของ script กันครับ #!/bin/sh # Simple SHELL script for Linux and UNIX system monitoring with # df command # ------------------------------------------------------------------------- # Copyright (c) 2009 mrGilL # This script is licensed under GNU GPL version [...]]]></description>
			<content:encoded><![CDATA[<p>สวัสดีครับต่อยอดจากเรื่อง <a href="http://imrgill.com/2009/12/11/monitor-server-with-sms-alert-shell-script" target="_blank">Server Down รู้ได้ทันทีผ่าน SMS แถมฟรี</a> ที่เขียนไว้วันก่อน วันนี้เอามาประยุกต์ให้ script เช็คสถานะของ hard disk ครับโดยให้ส่ง sms เตือนเมื่อมีการใช้งาน partition ใดๆ เกิน 90%<br />
มาดูตัว code ของ script กันครับ </p>
<pre>
<div class="codesnip-container" >#!/bin/sh
# Simple SHELL script for Linux and UNIX system monitoring with
# df command
# -------------------------------------------------------------------------
# Copyright (c) 2009 mrGilL <http://imrgill.com>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# Setup SMS User below
# See URL for more info:
# http://imrgill.com/2009/12/13/monitor-server-with-sms-alert-shell-script/
# -------------------------------------------------------------------------

# Hard type (hdx,sdx,scx)
HDD_TYPE="sd"

# Partition lists
PLIST=`df -h | grep $HDD_TYPE | awk '{ print $1 }' | sed -e 's/\/dev\///g'`

# Setting SMS User (Gmail)
GCUSER="user@gmail.com"
GCPASSWD="gmail-passwd" 

for p in $PLIST
do
  disk=$(df -h | grep $p | awk '{ print $5 }' | sed -e 's/\%//g')
  pname=$(df -h | grep $p | awk '{ print $6 }')
  if [ $disk -ge 90 ]; then
    # disk less than 90%
    wget --force-html --recursive --no-check-certificate -nd --delete-after "https://imrgill.com/google_sms/gsms.php?username=$GCUSER&#038;password=$GCPASSWD&#038;title=$(hostname) partition $pname < 90%"
  fi
done</div>
</pre>
<p><strong>วิธีนำไปใช้</strong></p>
<p>1. แก้ไข HDD_TYPE เป็นประเภท hard disk ที่คุณใช้ ดูได้จากคำสั่ง fdisk -l หรือ df ผลลัพธ์ที่ได้จะประมาณ /dev/sda ตัวอย่างผมได้ sda ให้ใส่เป็น HDD_TYPE=&#8221;sd&#8221;</p>
<pre>
<div class="codesnip-container" >[mrgill@Webserver ~]$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             59515556   1260296  55183232   3% /
/dev/sda8             11710104   2895576   8210084  27% /usr
/dev/sda7              1019208     37992    928608   4% /tmp
/dev/sda6            109109796   9092520  94385292   9% /var
/dev/sda5            287660612  11604092 261208448   5% /home
/dev/sda1               101086     33812     62055  36% /boot
tmpfs                   517284         0    517284   0% /dev/shm</div>
</pre>
<p>*เหตุผลที่ไม่ใส่ sda ไปตรงๆ เลยก็เพราะ กรณีมี hard disk หลายลูกเช่น sda, sdb ทำให้ script ไม่สามารถตรวจสอบ hard disk ที่เป็น sdb ได้</p>
<p>2. แก้ไข GCUSER และ GCPASSWD เป็น user gmail ของเรา</p>
<p>3. กำหนดสิทธิ์ให้สามารถรันได้</p>
<pre>
<div class="codesnip-container" >[root@Webserver ~]$ chmod +x <a href="http://imrgill.com/wp-content/uploads/2009/observman_disk.tar.bz2">observman_disk.sh</a></div>
</pre>
<p>4. นำ script ไปใส่ /etc/cron.daily/ เพื่อให้ script ทำงานทุกวัน</p>
<pre>
<div class="codesnip-container" >[root@Webserver ~]$ cp <a href="http://imrgill.com/wp-content/uploads/2009/observman_disk.tar.bz2">observman_disk.sh</a> /etc/cron.daily/</div>
</pre>
<p>หรือใครจะนำไปใส่ใน crontab ก็ไม่ว่ากัน</p>
<pre>
<div class="codesnip-container" >[root@Webserver ~]$ crontab -e</div>
</pre>
<pre>
<div class="codesnip-container" ># m h  dom mon dow   command
@daily /root/observman_disk.sh > /dev/null</div>
</pre>
<p>หวังว่าบทความนี้คงเป็นประโยชน์ต่อผู้อ่าน</p>
  
<div class="wp_license">
<p><a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/th/"><img src="http://i.creativecommons.org/l/by-nc-sa/3.0/th/88x31.png" alt="Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Thailand" class="alignleft" style="margin-top:4px;" />
</a>This work  is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/th/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Thailand</a>.</p>
</div>]]></content:encoded>
			<wfw:commentRss>http://imrgill.com/2009/12/13/shell-script-alert-sms-when-disk-small-left.html/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Server Down รู้ได้ทันทีผ่าน SMS แถมฟรีด้วย</title>
		<link>http://imrgill.com/2009/12/11/monitor-server-with-sms-alert-shell-script.html</link>
		<comments>http://imrgill.com/2009/12/11/monitor-server-with-sms-alert-shell-script.html#comments</comments>
		<pubDate>Fri, 11 Dec 2009 01:19:20 +0000</pubDate>
		<dc:creator>mrgill</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[sms]]></category>

		<guid isPermaLink="false">http://imrgill.com/?p=438</guid>
		<description><![CDATA[ก่อนอื่นขอหาวยาวๆ ก่อนกล่าวสวัสดีท่านผู้อ่านทุกท่าน  เมื่อคืนบ้าพลังอะไรไม่รู้อยากเขียน script ส่ง sms เตือนเมื่อ server down ที่จริงชาวบ้านเค้าก็ทำขายกันเยอะแยะ แต่หลังจากที่ผมได้ใช้ Google Calendar แล้วให้มันส่ง sms เตือนแถมฟรีอีก ก็เลยคิดอยากใช้ประโยชน์จากมันเพิ่มเติมก็ค้นๆ  Google อีกเช่นเคยครับ ไปเจอบทความใน ThaiAdmin เรื่อง google calendar sms ที่ท่าน smartsoft เขียนไว้ก็เลยลองโหลด Libraries Google Calendar SMS มาเล่นดูบ้าง ซึ่งเมื่อลองดูแล้วก็ถือว่าใช้งานง่ายทีเดียวเลยเอามาโมต่อ โดยให้ Shell Script เป็นตัว Submit form แทน ความสามารถของ Script 1. ส่ง sms แจ้งเตือนเมื่อ ping ไม่เจอ server 2. เก็บ log ในตัว เพราะทุกครั้งที่มันส่ง [...]]]></description>
			<content:encoded><![CDATA[<p>ก่อนอื่นขอหาวยาวๆ ก่อนกล่าวสวัสดีท่านผู้อ่านทุกท่าน  เมื่อคืนบ้าพลังอะไรไม่รู้อยากเขียน script ส่ง sms เตือนเมื่อ server down ที่จริงชาวบ้านเค้าก็ทำขายกันเยอะแยะ แต่หลังจากที่ผมได้ใช้ Google Calendar แล้วให้มันส่ง sms เตือนแถมฟรีอีก ก็เลยคิดอยากใช้ประโยชน์จากมันเพิ่มเติมก็ค้นๆ  Google อีกเช่นเคยครับ ไปเจอบทความใน ThaiAdmin เรื่อง <a href="http://www.thaiadmin.org/board/index.php?topic=114285.0">google calendar sms</a> ที่ท่าน <a title="ดูรายละเอียดของ smartsoft" href="http://www.thaiadmin.org/board/index.php?action=profile;u=25720">smartsoft</a> เขียนไว้ก็เลยลองโหลด Libraries Google Calendar SMS มาเล่นดูบ้าง ซึ่งเมื่อลองดูแล้วก็ถือว่าใช้งานง่ายทีเดียวเลยเอามาโมต่อ โดยให้ Shell Script เป็นตัว Submit form แทน</p>
<p><strong>ความสามารถของ Script</strong></p>
<p>1. ส่ง sms แจ้งเตือนเมื่อ ping ไม่เจอ server<br />
2. เก็บ log ในตัว เพราะทุกครั้งที่มันส่ง sms มันจะไปเพิ่ม Event ใน Google Calendar ทำให้เราเข้าไปตรวจสอบย้อนหลังได้<br />
3. ไม่ต้องเสียเงินค่าส่ง SMS แม้แต่น้อย (พี่ Google เค้าใจดี)</p>
<p><strong>มาดูขั้นตอนการทำกัน</strong></p>
<p>ก่อนอื่นเราก็ต้องไป Verify เบอร์มือถือใน Google Calendar ก่อนครับ ขออนุญาตท่าน <a title="ดูรายละเอียดของ smartsoft" href="http://www.thaiadmin.org/board/index.php?action=profile;u=25720">smartsoft</a> ทำรูปใหม่นะครับ<br />
1. ขั้นแรก ล็อกอินเข้า Google Calendar <a href="http://www.google.com/calendar" target="_blank">http://www.google.com/calendar</a> ก็ใช้ User ของ Gmail นั้นแหละครับ<br />
ล็อกอินแล้วคลิกที่ Settings เพื่อไปปรับเมนูให้เป็นภาษาไทย (หากใครเป็นภาษาไทยอยู่แล้วข้ามไปขั้นตอนต่อไปได้เลย)</p>
<p><img class="aligncenter" src="http://farm3.static.flickr.com/2773/4175582724_515d2cfce5_o.png" alt="" width="519" height="148" /></p>
<p style="text-align: center;">คลิก Settings</p>
<p>2. เลือก Language ให้เป็น <strong>ภาษาไทย </strong>แล้วกด Save</p>
<p style="text-align: center;"><img class="aligncenter" src="http://farm3.static.flickr.com/2774/4175582728_de23bb83d4_o.png" alt="" width="469" height="243" /></p>
<p style="text-align: center;">เลือก ภาษาไทย</p>
<p style="text-align: left;"><span id="more-438"></span>3. กลับมาหน้าปฏิทินคลิกที่ <strong>การตั้งค่า</strong></p>
<p style="text-align: left;"><img class="aligncenter" src="http://farm3.static.flickr.com/2785/4175582742_55962360a8_o.png" alt="" width="219" height="286" /></p>
<p style="text-align: left;">4. คลิกที่ <strong>ตั้งค่าอุปกรณ์เคลื่อนที่</strong></p>
<p style="text-align: left;"><img class="aligncenter" src="http://farm3.static.flickr.com/2516/4175582744_767056a6b0_o.png" alt="" width="317" height="177" /></p>
<p style="text-align: left;">
<p style="text-align: left;">5. กรอกเบอร์โทรศัพท์มือถือของคุณลงไป จากนั้นกดปุ่ม <strong>ส่งรหัสยืนยัน</strong></p>
<p style="text-align: left;"><img class="aligncenter" src="http://farm3.static.flickr.com/2745/4175582748_14b2eb8d46_o.png" alt="" width="527" height="223" /></p>
<p style="text-align: left;">6. รอสักครู่ Google จะส่ง SMS รหัสยืนยันมาให้ เมื่อได้รับรหัสยืนยันแล้วนำมากรอกในช่อง <strong>รหัสยืนยัน</strong> จากนั้นคลิก <strong>สิ้นสุดการตั้งค่า</strong></p>
<p style="text-align: center;"><strong><img class="aligncenter" src="http://farm3.static.flickr.com/2627/4175582752_3328f279a2_o.png" alt="" width="527" height="223" /></strong>กรอกรหัสยืนยันลงไป</p>
<p style="text-align: center;"><img class="aligncenter" src="http://farm3.static.flickr.com/2699/4174864937_66e118528c_o.png" alt="" width="563" height="61" />สถานะจะเปลี่ยนเป็นสีเขียวหลังยืนยันหมายเลขโทรศัพท์สำเร็จแล้ว</p>
<p style="text-align: left;"><strong><br />
</strong></p>
<p style="text-align: left;">7. คลิกที่แท็บ <strong>ปฎิทิน</strong> แล้วคลิกที่ <strong>การแจ้ง</strong></p>
<p style="text-align: left;"><img class="aligncenter" src="http://farm3.static.flickr.com/2509/4175583670_089b0611af_o.png" alt="" width="490" height="241" /></p>
<p style="text-align: left;">8. เลือก <strong>การแจ้งเตือนกิจกรรม</strong> ให้เป็น SMS  แล้วกด <strong>บันทึก </strong>(** สำคัญมาก คุณต้องเลือกให้เป็น SMS เป็นอันดับแรก)<strong><br />
</strong></p>
<p style="text-align: center;"><a href="http://farm3.static.flickr.com/2802/4175583674_3a5c7533c3_o.png" rel="lightbox[438]"><img class="aligncenter" src="http://farm3.static.flickr.com/2802/4175583674_3a5c7533c3_o.png" alt="" width="470" height="150" /></a></p>
<p>ตั้งเวลาตามใจชอบเลยครับ(ตรงนี้ไม่เกี่ยวกับ SMS Alert ใน Script ครับ)</p>
<p style="text-align: left;">เสร็จสิ้นสำหรับส่วนของ Google Calendar ครับต่อไปมาถึงตัว Shell Script กันบ้าง</p>
<p style="text-align: left;">ผมได้เอา Script ของ <span>Vivek Gite แห่ง </span><a href="http://cyberciti.biz" target="_blank">cyberciti.biz</a> มาแก้ไขนิดหน่อยครับ ต้นฉบับอยู่ที่ <a href="http://bash.cyberciti.biz/monitoring/monitor-windows-linux-server-with-ping-script/" target="_blank">http://bash.cyberciti.biz/monitoring/monitor-windows-linux-server-with-ping-script/</a></p>
<p>ผมตั้งชื่อ Shell Script ตัวนี้ว่า <a href="http://imrgill.com//wp-content/uploads/2009/observman.tar.bz2">observman.sh</a> &lt;&lt;กดดาวน์โหลด</p>
<pre>
<div class="codesnip-container" >#!/bin/bash
# Simple SHELL script for Linux and UNIX system monitoring with
# ping command
# -------------------------------------------------------------------------
# Copyright (c) 2006 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# Modify by mrGilL
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Setup SMS User below
# See URL for more info:
# http://www.cyberciti.biz/tips/simple-linux-and-unix-system-monitoring-with-ping-command-and-scripts.html
# http://imrgill.com/2009/12/11/monitor-server-with-sms-alert-shell-script/
# -------------------------------------------------------------------------

# add ip / hostname separated by blank space
HOSTS="192.168.1.2 eng.ru.ac.th imrgill.com www.pca.co.th"

# no ping request
COUNT=5

# Set SMS Username (Google Calendar)
GCUSER="user@gmail.com"
GCPASSWD="gmail-passwd" 

for myHost in $HOSTS
do
  count=$(ping -c $COUNT $myHost | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
  if [ $count -eq 0 ]; then
    # 100% failed
    wget --force-html --recursive --no-check-certificate -nd --delete-after "https://imrgill.com/google_sms/gsms.php?username=$GCUSER&amp;password=$GCPASSWD&amp;title=Server $myHost Down"
  fi
done</div>
</pre>
<p>ใส่ IP หรือชื่อ Host ของ Server ที่ต้องการ Monitor ลงไป หากมีหลายเครื่องให้คั่นด้วยเว้นวรรค</p>
<p>ต่อมาแก้ไข GCUSER และ GCPASSWD เป็นของท่าน(Gmail ของท่าน)</p>
<p>อย่าลืมกำหนดสิทธิ์ให้มันรันได้ด้วยนะครับ</p>
<pre>
<div class="codesnip-container" >root@mrgill-laptop:/root# chmod +x observman.sh</div>
</pre>
<p>สุดท้ายจับ Shell Script ของเราใส่ใน Crontab โดย</p>
<pre>
<div class="codesnip-container" >root@mrgill-laptop:~# crontab -e</div>
</pre>
<p>ผมตั้งให้มันเช็คทุก 15 นาทีครับ</p>
<pre>
<div class="codesnip-container" ># m h  dom mon dow   command
0-59/15 * * * * /root/observman.sh &gt; /dev/null</div>
</pre>
<p>ลองทดสอบง่ายๆ ดูครับ ใช้ไอพีเครื่องในวงแลนคุณก็ได้ จากนั้นไป disable การ์ดแลนหรือจะถอดสายแลนของเครื่องที่คุณต้องการ Monitor ก็ได้ รอประมาณ 2 นาทีจะมี SMS ส่งจาก Google มาหาคุณ</p>
<p style="text-align: left;"><strong>ภาพตัวอย่างหากแก้ไขถูกต้องครับ</strong></p>
<p style="text-align: center;"><img class="aligncenter" src="http://farm5.static.flickr.com/4025/4210341646_7a76249947_o.png" alt="" width="486" height="300" /><br />
จะมี event add เข้าไปใน google calendar</p>
<p style="text-align: center;"><img class="aligncenter" src="http://farm3.static.flickr.com/2554/4210341648_3b51cc4c89_o.jpg" alt="" width="640" height="480" /><br />
ภาพข้อความจาก google sms</p>
<p>*หมายเหตุ  : มีคนถามมาว่าทำไมต้องส่งข้อมูลผ่าน blog ผมด้วย ส่งเข้า Google เลยไม่ได้เหรอ คำตอบก็คือมันต้องมี API ติดต่อไปยัง Google Calendar ครับ ซึ่งผมได้ฝังไว้บน blog ของผมเอง และหากใครกังวลเรื่องความปลอดภัยผมเองก็มีไฟล์ API ให้โหลดเอาไว้ติดตั้งบน Server ตัวเองได้ครับซึ่งสามารถดาวน์โหลดได้จากที่นี่ <a href="http://imrgill.com/wp-content/uploads/2009/google_sms.tar.bz2">google_sms.tar.bz2</a> โหลดเสร็จแล้วก็เอาไปแตกไว้ใน wwwroot และอย่าลืมไปแก้ URL  ใน Shell Script ด้วยนะครับ</p>
<p>หวังว่าบทความนี้คงเป็นประโยชน์กับผู้อ่าน<br />
แหล่งข้อมูล : <a href="http://www.thaiadmin.org/board/index.php?topic=114285.0">http://www.thaiadmin.org/board/index.php?topic=114285.0</a><br />
<a href="http://bash.cyberciti.biz/monitoring/monitor-windows-linux-server-with-ping-script/">http://bash.cyberciti.biz/monitoring/monitor-windows-linux-server-with-ping-script/</a></p>
  
<div class="wp_license">
<p><a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/th/"><img src="http://i.creativecommons.org/l/by-nc-sa/3.0/th/88x31.png" alt="Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Thailand" class="alignleft" style="margin-top:4px;" />
</a>This work  is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/th/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Thailand</a>.</p>
</div>]]></content:encoded>
			<wfw:commentRss>http://imrgill.com/2009/12/11/monitor-server-with-sms-alert-shell-script.html/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
	</channel>
</rss>
