<?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; bash</title>
	<atom:link href="http://imrgill.com/tag/bash/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>Tweeting แบบดิบๆ ผ่าน Linux Command Line</title>
		<link>http://imrgill.com/2009/12/30/tweeting-via-linux-command-line.html</link>
		<comments>http://imrgill.com/2009/12/30/tweeting-via-linux-command-line.html#comments</comments>
		<pubDate>Wed, 30 Dec 2009 14:58:04 +0000</pubDate>
		<dc:creator>mrgill</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[shell script]]></category>
		<category><![CDATA[status]]></category>
		<category><![CDATA[tweet]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://imrgill.com/?p=515</guid>
		<description><![CDATA[เมื่อกี้เข้า linuxtoday.com ไปเจอทิปเด็ดๆ ใน junauza.com เรื่อง Follow Me: Tweeting from the Linux Command Line อ่านแล้วน่าสนใจดี และหลังจากลองแล้วก็ได้ผลครับเลยนำมาบอกต่อ ขั้นตอนเขามีอยู่ว่า 1. ติดตั้ง curl mrgill@mrgill-laptop:~$ sudo apt-get install curl 2. สร้างไฟล์ชื่อ twitter ไว้ใน /usr/bin/ ด้วย text editor ที่ชอบในตัวอย่างเขาใช้ gedit แต่ผมชอบ nano mrgill@mrgill-laptop:~$ sudo nano /usr/bin/twitter จากนั้นนำโค้ดด้านล่างไปวาง curl --basic --user "yourusername:yourpasswd" --data-ascii "status=`echo $@&#124;tr ' ' '+'`" "http://twitter.com/statuses/update.json" -o /dev/null; [...]]]></description>
			<content:encoded><![CDATA[<p>เมื่อกี้เข้า <a href="http://www.linuxtoday.com/">linuxtoday.com</a> ไปเจอทิปเด็ดๆ ใน <a href="http://www.junauza.com/2009/12/most-popular-tips-and-tricks-of-2009.html">junauza.com</a> เรื่อง <a href="http://www.junauza.com/2009/03/follow-me-twitting-from-linux-command.html">Follow Me: Tweeting from the Linux Command Line</a> อ่านแล้วน่าสนใจดี และหลังจากลองแล้วก็ได้ผลครับเลยนำมาบอกต่อ</p>
<p>ขั้นตอนเขามีอยู่ว่า<br />
1. ติดตั้ง curl</p>
<pre>
<div class="codesnip-container" >mrgill@mrgill-laptop:~$ sudo apt-get install curl</div>
</pre>
<p>2. สร้างไฟล์ชื่อ twitter ไว้ใน /usr/bin/ ด้วย text editor ที่ชอบในตัวอย่างเขาใช้ gedit แต่ผมชอบ nano</p>
<pre>
<div class="codesnip-container" >mrgill@mrgill-laptop:~$ sudo nano /usr/bin/twitter</div>
</pre>
<p>จากนั้นนำโค้ดด้านล่างไปวาง</p>
<pre>
<div class="codesnip-container" >curl --basic --user <em>"yourusername:yourpasswd"</em> --data-ascii "status=`echo $@|tr ' ' '+'`" "http://twitter.com/statuses/update.json" -o /dev/null; echo Message Sent!</div>
</pre>
<p>*อย่าลืมเปลี่ยน yourusername กับ yourpasswd เป็นของ twitter ของคุณ (กด Ctrl + O เพื่อบันทึก และกด Ctrl + X เพื่อออก)</p>
<p>3. กำหนดสิทธิ์ให้ /usr/bin/twitter สามารถรันได้<br />
<span id="more-515"></span>
<pre>
<div class="codesnip-container" >mrgill@mrgill-laptop:~$ sudo chmod +x /usr/bin/twitter</div>
</pre>
<p>4. ทดลอง tweeting กันเลย โดยพิมพ์ twitter เว้นวรรค ข้อความของคุณ</p>
<pre>
<div class="codesnip-container" >mrgill@mrgill-laptop:~$ twitter test tweet from command lind</div>
</pre>
<p style="text-align: left;"><a href="http://www.flickr.com/photos/imrgill/4228553402/sizes/o/"><img class="aligncenter" src="http://farm3.static.flickr.com/2491/4228553402_564196e4f9_o.png" alt="" width="595" height="410" /></a></p>
<p style="text-align: center;">ภาพตัวอย่างคำสั่ง twitter</p>
<p style="text-align: left;"><a href="http://www.flickr.com/photos/imrgill/4228553404/sizes/o/"><img class="aligncenter" src="http://farm3.static.flickr.com/2621/4228553404_4715fffda5_o.png" alt="" width="566" height="380" /></a></p>
<p style="text-align: center;">tweet บน twitter.com</p>
<p style="text-align: left;">5. ขอให้สนุกกับการ tweet</p>
<p style="text-align: left;">
<p style="text-align: left;">แหล่งข้อมูล : <a href="http://www.junauza.com/2009/03/follow-me-twitting-from-linux-command.html" target="_blank">http://www.junauza.com/2009/03/follow-me-twitting-from-linux-command.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://imrgill.com/2009/12/30/tweeting-via-linux-command-line.html/feed/</wfw:commentRss>
		<slash:comments>1</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>
