<?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>TECH.kulish.com &#187; MySQL</title>
	<atom:link href="http://tech.kulish.com/category/databases/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.kulish.com</link>
	<description>Technical Goulash</description>
	<lastBuildDate>Thu, 01 Dec 2011 00:39:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>irc.diff.05142011.2.txt</title>
		<link>http://tech.kulish.com/2011/05/14/irc-diff-05142011-2-txt/</link>
		<comments>http://tech.kulish.com/2011/05/14/irc-diff-05142011-2-txt/#comments</comments>
		<pubDate>Sun, 15 May 2011 04:57:57 +0000</pubDate>
		<dc:creator>Null</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://tech.kulish.com/?p=319</guid>
		<description><![CDATA[Index: irc.php =================================================================== --- irc.php (revision 2317) +++ irc.php (working copy) @@ -1,10 +1,6 @@ #!/usr/bin/env php -# status -# reboot -# log -# help -# down +# port_info is broken. always reports same values no matter host selected]]></description>
			<content:encoded><![CDATA[<p><code><br />
Index: irc.php<br />
===================================================================<br />
--- irc.php	(revision 2317)<br />
+++ irc.php	(working copy)<br />
@@ -1,10 +1,6 @@<br />
 #!/usr/bin/env php</p>
<p>-# status <dev prt srv><br />
-# reboot<br />
-# log<br />
-# help<br />
-# down<br />
+# port_info is broken.  always reports same values no matter host selected</p>
<p> <?php</p>
<p>@@ -23,14 +19,33 @@<br />
 # Redirect to /dev/null if you aren't using screen to keep tabs<br />
 echo "Observer Bot Starting ...\n";<br />
 echo "\n";<br />
-echo "COMMAND\t\tHOST\t\t\tDEVICE\n";<br />
-echo "-------\t\t----\t\t\t------\n";<br />
+echo "Timestamp         Command\n";<br />
+echo "----------------- ------- \n";</p>
<p> class observiumbot</p>
<p> {</p>
<p>+<br />
 ###<br />
+# Get HELP!<br />
+###<br />
+  function help_info(&#038;$irc, &#038;$data)<br />
+  {<br />
+<br />
+global $config;<br />
+<br />
+$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Commands: !help, !log, !status, !version, !down, !port, !device, !listdevices");<br />
+<br />
+echo date("m-d-y H:i:s ");<br />
+echo "HELP\n";<br />
+<br />
+mysql_close();<br />
+<br />
+  }<br />
+<br />
+<br />
+###<br />
 # Get status on !version<br />
 ###<br />
   function version_info(&#038;$irc, &#038;$data)<br />
@@ -40,6 +55,7 @@</p>
<p> $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Observium Version " . $config['version']);</p>
<p>+echo date("m-d-y H:i:s ");<br />
 echo "VERSION\t\t". $config['version'] . "\n";</p>
<p> mysql_close();<br />
@@ -47,6 +63,31 @@<br />
   }</p>
<p> ###<br />
+# Get last eventlog entry<br />
+###<br />
+  function log_info(&#038;$irc, &#038;$data)<br />
+  {<br />
+<br />
+global $config;<br />
+<br />
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);<br />
+mysql_select_db($config['db_name']);<br />
+<br />
+    $device = dbFetchRow("SELECT `event_id`,`host`,`datetime`,`message`,`type` FROM `eventlog` ORDER BY `event_id` DESC LIMIT 1");<br />
+     $host=$device['host'];<br />
+     $hostid = dbFetchRow("SELECT `hostname` FROM `devices` WHERE `device_id` = $host");<br />
+<br />
+$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $device['event_id'] ." ". $hostid['hostname'] ." ". $device['datetime'] ." ". $device['message'] ." ". $device['type']);<br />
+<br />
+echo date("m-d-y H:i:s ");<br />
+echo "LOG\n";<br />
+<br />
+mysql_close();<br />
+<br />
+  }<br />
+<br />
+<br />
+###<br />
 # Get status on !down devices<br />
 ###<br />
   function down_info(&#038;$irc, &#038;$data)<br />
@@ -56,18 +97,16 @@<br />
 mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);<br />
 mysql_select_db($config['db_name']);</p>
<p>-    $query = mysql_query("SELECT * FROM `devices` where status=0");<br />
-    unset($message);<br />
-    while($device = mysql_fetch_assoc($query))<br />
+    foreach (dbFetchRows("SELECT * FROM `devices` where status=0") as $device)<br />
     {<br />
       $message .= $sep . $device['hostname'];<br />
       $sep = ", ";<br />
     }<br />
     $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);<br />
-    unset($sep);</p>
<p> mysql_close();</p>
<p>+echo date("m-d-y H:i:s ");<br />
 echo "DOWN\n";</p>
<p>   }<br />
@@ -92,9 +131,10 @@<br />
     if ($device['ignore']) { $status = "*Ignored*"; }<br />
     if ($device['disabled']) { $status = "*Disabled*"; }</p>
<p>-    $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .<br />
+    $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $device['os'] . " " . $device['version'] . " " .<br />
       $device['features'] . " " . $status);</p>
<p>+echo date("m-d-y H:i:s ");<br />
 echo "DEVICE\t\t". $device['hostname']."\n";</p>
<p>   }<br />
@@ -122,10 +162,11 @@<br />
     $pps_in = format_bi($port['ifInUcastPkts_rate']);<br />
     $pps_out = format_bi($port['ifOutUcastPkts_rate']);</p>
<p>-    $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .<br />
+    $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .<br />
       $bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps");</p>
<p>-echo "PORT\t\t" . $hostname . "\t". $ifname . "\n";<br />
+echo date("m-d-y H:i:s ");<br />
+echo "PORT\t\t\t" . $hostname . "\t". $ifname . "\n";</p>
<p>   }</p>
<p>@@ -152,9 +193,58 @@<br />
     $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);<br />
     unset($sep);</p>
<p>+echo date("m-d-y H:i:s ");<br />
 echo "LISTDEVICES\n";</p>
<p>   }<br />
+<br />
+<br />
+###<br />
+# !status <dev prt srv> gives overall status<br />
+###<br />
+  function status_info(&#038;$irc, &#038;$data)<br />
+  {<br />
+    $statustype = $data->messageex[1];<br />
+<br />
+global $config;<br />
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);<br />
+mysql_select_db($config['db_name']);<br />
+<br />
+    if ($statustype == "dev") {<br />
+        $devcount = array_pop(dbFetchRow("SELECT count(*) FROM devices"));<br />
+        $devup = array_pop(dbFetchRow("SELECT count(*) FROM devices  WHERE status = '1' AND `ignore` = '0'"));<br />
+        $devdown = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE status = '0' AND `ignore` = '0'"));<br />
+        $devign = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `ignore` = '1'"));<br />
+        $devdis = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `disabled` = '1'"));<br />
+        $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Devices: " .$devcount . " (" .$devup . " up, " .$devdown . " down, " .$devign . " ignored, " .$devdis . " disabled" . ")"); }<br />
+<br />
+    else if ($statustype == "prt") {<br />
+        $prtcount = array_pop(dbFetchRow("SELECT count(*) FROM ports"));<br />
+        $prtup = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D  WHERE I.ifOperStatus = 'up' AND I.ignore = '0' AND I.device_id = D.device_id AND D.ignore = '0'"));<br />
+        $prtdown = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifOperStatus = 'down' AND I.ifAdminStatus = 'up' AND I.ignore = '0' AND D.device_id = I.device_id AND D.ignore = '0'"));<br />
+        $prtsht = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifAdminStatus = 'down' AND I.ignore = '0' AND D.device_id = I.device_id AND D.ignore = '0'"));<br />
+        $prtign = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE D.device_id = I.device_id AND (I.ignore = '1' OR D.ignore = '1')"));<br />
+        $prterr = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE D.device_id = I.device_id AND (I.ignore = '0' OR D.ignore = '0') AND (I.ifInErrors_delta > '0' OR I.ifOutErrors_delta > '0')"));<br />
+        $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Ports: " .$prtcount . " (" .$prtup . " up, " .$prtdown . " down, " .$prtign . " ignored, " .$prtsht . " shutdown" . ")");}<br />
+<br />
+    else if ($statustype == "srv") {<br />
+        $srvcount = array_pop(dbFetchRow("SELECT count(service_id) FROM services"));<br />
+        $srvup = array_pop(dbFetchRow("SELECT count(service_id) FROM services  WHERE service_status = '1' AND service_ignore ='0'"));<br />
+        $srvdown = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_status = '0' AND service_ignore = '0'"));<br />
+        $srvign = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_ignore = '1'"));<br />
+        $srvdis = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_disabled = '1'"));<br />
+        $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Services: " .$srvcount . " (" .$srvup . " up, " .$srvdown . " down, " .$srvign . " ignored, " .$srvdis . " disabled" . ")"); }<br />
+<br />
+    else {<br />
+        $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Error: STATUS requires one of the following <dev prt srv>"); }<br />
+<br />
+mysql_close();<br />
+<br />
+echo date("m-d-y H:i:s ");<br />
+echo "STATUS\t\t$statustype\n";<br />
+<br />
+  }<br />
+<br />
 }</p>
<p> $bot = &#038;new observiumbot();<br />
@@ -166,6 +256,9 @@<br />
 $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info');<br />
 $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!down', $bot, 'down_info');<br />
 $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!version', $bot, 'version_info');<br />
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!status', $bot, 'status_info');<br />
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!log', $bot, 'log_info');<br />
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!help', $bot, 'help_info');</p>
<p> $irc->connect($config['irc_host'], $config['irc_port']);<br />
 $irc->login($config['irc_nick'], 'Observium Bot', 0, $config['irc_nick']);<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.kulish.com/2011/05/14/irc-diff-05142011-2-txt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>irc.diff.05142011.1.txt</title>
		<link>http://tech.kulish.com/2011/05/14/irc-diff-05142011-1-txt/</link>
		<comments>http://tech.kulish.com/2011/05/14/irc-diff-05142011-1-txt/#comments</comments>
		<pubDate>Sun, 15 May 2011 04:56:47 +0000</pubDate>
		<dc:creator>Null</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://tech.kulish.com/?p=316</guid>
		<description><![CDATA[Index: irc.php =================================================================== --- irc.php (revision 2317) +++ irc.php (working copy) @@ -1,11 +1,5 @@ #!/usr/bin/env php -# status -# reboot -# log -# help -# down -]]></description>
			<content:encoded><![CDATA[<p><code><br />
Index: irc.php<br />
===================================================================<br />
--- irc.php	(revision 2317)<br />
+++ irc.php	(working copy)<br />
@@ -1,11 +1,5 @@<br />
 #!/usr/bin/env php</p>
<p>-# status <dev prt srv><br />
-# reboot<br />
-# log<br />
-# help<br />
-# down<br />
-<br />
 <?php</p>
<p> # Disable annoying messages... well... all messages actually :)<br />
@@ -23,14 +17,33 @@<br />
 # Redirect to /dev/null if you aren't using screen to keep tabs<br />
 echo "Observer Bot Starting ...\n";<br />
 echo "\n";<br />
-echo "COMMAND\t\tHOST\t\t\tDEVICE\n";<br />
-echo "-------\t\t----\t\t\t------\n";<br />
+echo "Timestamp         Command\n";<br />
+echo "----------------- ------- \n";</p>
<p> class observiumbot</p>
<p> {</p>
<p>+<br />
 ###<br />
+# Get HELP!<br />
+###<br />
+  function help_info(&#038;$irc, &#038;$data)<br />
+  {<br />
+<br />
+global $config;<br />
+<br />
+$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Commands: !help, !log, !status, !version, !down, !port, !device, !listdevices");<br />
+<br />
+echo date("m-d-y H:i:s ");<br />
+echo "HELP\n";<br />
+<br />
+mysql_close();<br />
+<br />
+  }<br />
+<br />
+<br />
+###<br />
 # Get status on !version<br />
 ###<br />
   function version_info(&#038;$irc, &#038;$data)<br />
@@ -40,6 +53,7 @@</p>
<p> $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Observium Version " . $config['version']);</p>
<p>+echo date("m-d-y H:i:s ");<br />
 echo "VERSION\t\t". $config['version'] . "\n";</p>
<p> mysql_close();<br />
@@ -47,6 +61,31 @@<br />
   }</p>
<p> ###<br />
+# Get last eventlog entry<br />
+###<br />
+  function log_info(&#038;$irc, &#038;$data)<br />
+  {<br />
+<br />
+global $config;<br />
+<br />
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);<br />
+mysql_select_db($config['db_name']);<br />
+<br />
+    $device = dbFetchRow("SELECT `event_id`,`host`,`datetime`,`message`,`type` FROM `eventlog` ORDER BY `event_id` DESC LIMIT 1");<br />
+     $host=$device['host'];<br />
+     $hostid = dbFetchRow("SELECT `hostname` FROM `devices` WHERE `device_id` = $host");<br />
+<br />
+$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $device['event_id'] ." ". $hostid['hostname'] ." ". $device['datetime'] ." ". $device['message'] ." ". $device['type']);<br />
+<br />
+echo date("m-d-y H:i:s ");<br />
+echo "LOG\n";<br />
+<br />
+mysql_close();<br />
+<br />
+  }<br />
+<br />
+<br />
+###<br />
 # Get status on !down devices<br />
 ###<br />
   function down_info(&#038;$irc, &#038;$data)<br />
@@ -56,18 +95,16 @@<br />
 mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);<br />
 mysql_select_db($config['db_name']);</p>
<p>-    $query = mysql_query("SELECT * FROM `devices` where status=0");<br />
-    unset($message);<br />
-    while($device = mysql_fetch_assoc($query))<br />
+    foreach (dbFetchRows("SELECT * FROM `devices` where status=0") as $device)<br />
     {<br />
       $message .= $sep . $device['hostname'];<br />
       $sep = ", ";<br />
     }<br />
     $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);<br />
-    unset($sep);</p>
<p> mysql_close();</p>
<p>+echo date("m-d-y H:i:s ");<br />
 echo "DOWN\n";</p>
<p>   }<br />
@@ -92,9 +129,10 @@<br />
     if ($device['ignore']) { $status = "*Ignored*"; }<br />
     if ($device['disabled']) { $status = "*Disabled*"; }</p>
<p>-    $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .<br />
+    $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $device['os'] . " " . $device['version'] . " " .<br />
       $device['features'] . " " . $status);</p>
<p>+echo date("m-d-y H:i:s ");<br />
 echo "DEVICE\t\t". $device['hostname']."\n";</p>
<p>   }<br />
@@ -122,10 +160,11 @@<br />
     $pps_in = format_bi($port['ifInUcastPkts_rate']);<br />
     $pps_out = format_bi($port['ifOutUcastPkts_rate']);</p>
<p>-    $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .<br />
+    $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .<br />
       $bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps");</p>
<p>-echo "PORT\t\t" . $hostname . "\t". $ifname . "\n";<br />
+echo date("m-d-y H:i:s ");<br />
+echo "PORT\t\t\t" . $hostname . "\t". $ifname . "\n";</p>
<p>   }</p>
<p>@@ -152,9 +191,58 @@<br />
     $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);<br />
     unset($sep);</p>
<p>+echo date("m-d-y H:i:s ");<br />
 echo "LISTDEVICES\n";</p>
<p>   }<br />
+<br />
+<br />
+###<br />
+# !status <dev prt srv> gives overall status<br />
+###<br />
+  function status_info(&#038;$irc, &#038;$data)<br />
+  {<br />
+    $statustype = $data->messageex[1];<br />
+<br />
+global $config;<br />
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);<br />
+mysql_select_db($config['db_name']);<br />
+<br />
+    if ($statustype == "dev") {<br />
+        $devcount = array_pop(dbFetchRow("SELECT count(*) FROM devices"));<br />
+        $devup = array_pop(dbFetchRow("SELECT count(*) FROM devices  WHERE status = '1' AND `ignore` = '0'"));<br />
+        $devdown = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE status = '0' AND `ignore` = '0'"));<br />
+        $devign = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `ignore` = '1'"));<br />
+        $devdis = array_pop(dbFetchRow("SELECT count(*) FROM devices WHERE `disabled` = '1'"));<br />
+        $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Devices: " .$devcount . " (" .$devup . " up, " .$devdown . " down, " .$devign . " ignored, " .$devdis . " disabled" . ")"); }<br />
+<br />
+    else if ($statustype == "prt") {<br />
+        $prtcount = array_pop(dbFetchRow("SELECT count(*) FROM ports"));<br />
+        $prtup = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D  WHERE I.ifOperStatus = 'up' AND I.ignore = '0' AND I.device_id = D.device_id AND D.ignore = '0'"));<br />
+        $prtdown = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifOperStatus = 'down' AND I.ifAdminStatus = 'up' AND I.ignore = '0' AND D.device_id = I.device_id AND D.ignore = '0'"));<br />
+        $prtsht = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE I.ifAdminStatus = 'down' AND I.ignore = '0' AND D.device_id = I.device_id AND D.ignore = '0'"));<br />
+        $prtign = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE D.device_id = I.device_id AND (I.ignore = '1' OR D.ignore = '1')"));<br />
+        $prterr = array_pop(dbFetchRow("SELECT count(*) FROM ports AS I, devices AS D WHERE D.device_id = I.device_id AND (I.ignore = '0' OR D.ignore = '0') AND (I.ifInErrors_delta > '0' OR I.ifOutErrors_delta > '0')"));<br />
+        $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Ports: " .$prtcount . " (" .$prtup . " up, " .$prtdown . " down, " .$prtign . " ignored, " .$prtsht . " shutdown" . ")");}<br />
+<br />
+    else if ($statustype == "srv") {<br />
+        $srvcount = array_pop(dbFetchRow("SELECT count(service_id) FROM services"));<br />
+        $srvup = array_pop(dbFetchRow("SELECT count(service_id) FROM services  WHERE service_status = '1' AND service_ignore ='0'"));<br />
+        $srvdown = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_status = '0' AND service_ignore = '0'"));<br />
+        $srvign = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_ignore = '1'"));<br />
+        $srvdis = array_pop(dbFetchRow("SELECT count(service_id) FROM services WHERE service_disabled = '1'"));<br />
+        $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Services: " .$srvcount . " (" .$srvup . " up, " .$srvdown . " down, " .$srvign . " ignored, " .$srvdis . " disabled" . ")"); }<br />
+<br />
+    else {<br />
+        $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Error: STATUS requires one of the following <dev prt srv>"); }<br />
+<br />
+mysql_close();<br />
+<br />
+echo date("m-d-y H:i:s ");<br />
+echo "STATUS\t\t$statustype\n";<br />
+<br />
+  }<br />
+<br />
 }</p>
<p> $bot = &#038;new observiumbot();<br />
@@ -166,6 +254,9 @@<br />
 $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info');<br />
 $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!down', $bot, 'down_info');<br />
 $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!version', $bot, 'version_info');<br />
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!status', $bot, 'status_info');<br />
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!log', $bot, 'log_info');<br />
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!help', $bot, 'help_info');</p>
<p> $irc->connect($config['irc_host'], $config['irc_port']);<br />
 $irc->login($config['irc_nick'], 'Observium Bot', 0, $config['irc_nick']);<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.kulish.com/2011/05/14/irc-diff-05142011-1-txt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>irc.diff.05142011.txt</title>
		<link>http://tech.kulish.com/2011/05/14/irc-diff-05142011-txt/</link>
		<comments>http://tech.kulish.com/2011/05/14/irc-diff-05142011-txt/#comments</comments>
		<pubDate>Sun, 15 May 2011 04:55:49 +0000</pubDate>
		<dc:creator>Null</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://tech.kulish.com/?p=312</guid>
		<description><![CDATA[Index: irc.php =================================================================== --- irc.php (revision 2284) +++ irc.php (working copy) @@ -1,37 +1,122 @@ #!/usr/bin/env php + +# status +# reboot +# log +# help +# down +]]></description>
			<content:encoded><![CDATA[<p><code><br />
Index: irc.php<br />
===================================================================<br />
--- irc.php	(revision 2284)<br />
+++ irc.php	(working copy)<br />
@@ -1,37 +1,122 @@<br />
 #!/usr/bin/env php<br />
+<br />
+# status <dev prt srv><br />
+# reboot<br />
+# log<br />
+# help<br />
+# down<br />
+<br />
 <?php</p>
<p>-include("includes/defaults.inc.php");<br />
-include("config.php");<br />
-include("includes/functions.php");<br />
-include("includes/discovery/functions.inc.php");<br />
+# Disable annoying messages... well... all messages actually :)<br />
+error_reporting(0);</p>
<p>+include_once("includes/defaults.inc.php");<br />
+include_once("config.php");<br />
+include_once("includes/functions.php");<br />
+include_once("includes/discovery/functions.inc.php");<br />
+<br />
 include_once('Net/SmartIRC.php');</p>
<p>+mysql_close();<br />
+<br />
+# Redirect to /dev/null if you aren't using screen to keep tabs<br />
+echo "Observer Bot Starting ...\n";<br />
+echo "\n";<br />
+echo "COMMAND\t\tHOST\t\t\tDEVICE\n";<br />
+echo "-------\t\t----\t\t\t------\n";<br />
+<br />
 class observiumbot<br />
+<br />
 {<br />
+<br />
+###<br />
+# Get status on !version<br />
+###<br />
+  function version_info(&#038;$irc, &#038;$data)<br />
+  {<br />
+<br />
+global $config;<br />
+<br />
+$irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, "Observium Version " . $config['version']);<br />
+<br />
+echo "VERSION\t\t". $config['version'] . "\n";<br />
+<br />
+mysql_close();<br />
+<br />
+  }<br />
+<br />
+###<br />
+# Get status on !down devices<br />
+###<br />
+  function down_info(&#038;$irc, &#038;$data)<br />
+  {<br />
+<br />
+global $config;<br />
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);<br />
+mysql_select_db($config['db_name']);<br />
+<br />
+    $query = mysql_query("SELECT * FROM `devices` where status=0");<br />
+    unset($message);<br />
+    while($device = mysql_fetch_assoc($query))<br />
+    {<br />
+      $message .= $sep . $device['hostname'];<br />
+      $sep = ", ";<br />
+    }<br />
+    $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);<br />
+    unset($sep);<br />
+<br />
+mysql_close();<br />
+<br />
+echo "DOWN\n";<br />
+<br />
+  }<br />
+<br />
+###<br />
+# Get status on !device <hostname><br />
+###<br />
   function device_info(&#038;$irc, &#038;$data)<br />
   {<br />
+<br />
     $hostname = $data->messageex[1];</p>
<p>-    $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'"));<br />
+global $config;<br />
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);<br />
+mysql_select_db($config['db_name']);</p>
<p>+    $device = dbFetchRow("SELECT * FROM `devices` WHERE `hostname` = ?",array($hostname));<br />
+<br />
+mysql_close();<br />
+<br />
     if ($device['status'] == 1) { $status = "Up " . formatUptime($device['uptime'] . " "); } else { $status = "Down "; }<br />
     if ($device['ignore']) { $status = "*Ignored*"; }<br />
     if ($device['disabled']) { $status = "*Disabled*"; }</p>
<p>     $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#'.$device['device_id'] . " " . $device['os'] . " " . $device['version'] . " " .<br />
       $device['features'] . " " . $status);<br />
+<br />
+echo "DEVICE\t\t". $device['hostname']."\n";<br />
+<br />
   }</p>
<p>+<br />
+###<br />
+# Get status on !port <hostname port><br />
+###<br />
   function port_info(&#038;$irc, &#038;$data)<br />
   {<br />
     $hostname = $data->messageex[1];<br />
     $ifname = $data->messageex[2];</p>
<p>-    $device = mysql_fetch_assoc(mysql_query("SELECT * FROM `devices` WHERE `hostname` = '".mres($hostname)."'"));<br />
-    $port   = mysql_fetch_assoc(mysql_query("SELECT * FROM `ports` WHERE `ifName` = '".mres($ifname)."' OR `ifDescr` = '".mres($ifname)."' AND device_id = '".$device['device_id']."'"));<br />
+global $config;<br />
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);<br />
+mysql_select_db($config['db_name']);</p>
<p>+    $device = dbFetchRow("SELECT * FROM `devices` WHERE `hostname` = ?",array($device));<br />
+    $port   = dbFetchRow("SELECT * FROM `ports` WHERE `ifName` = ? OR `ifDescr` = ? AND device_id = ?", array($ifname, $ifname, $device['device_id']));<br />
+<br />
+mysql_close();<br />
+<br />
     $bps_in = formatRates($port['ifInOctets_rate']);<br />
     $bps_out = formatRates($port['ifOutOctets_rate']);<br />
     $pps_in = format_bi($port['ifInUcastPkts_rate']);<br />
@@ -39,19 +124,36 @@</p>
<p>     $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, '#' . $port['interface_id'] . " " . $port['ifAdminStatus'] . "/" . $port['ifOperStatus'] . " " .<br />
       $bps_in. " > bps > " . $bps_out . " | " . $pps_in. "pps > PPS > " . $pps_out ."pps");<br />
+<br />
+echo "PORT\t\t" . $hostname . "\t". $ifname . "\n";<br />
+<br />
   }</p>
<p>+<br />
+###<br />
+# !listdevices lists all devices<br />
+###<br />
   function list_devices(&#038;$irc, &#038;$data)<br />
   {<br />
-    $query = mysql_query("SELECT * FROM `devices`");<br />
-    unset($message);<br />
-    while($device = mysql_fetch_assoc($query))<br />
+    unset ($message);<br />
+<br />
+global $config;<br />
+mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']);<br />
+mysql_select_db($config['db_name']);<br />
+<br />
+    foreach (dbFetchRows("SELECT `hostname` FROM `devices`") as $device)<br />
     {<br />
       $message .= $sep . $device['hostname'];<br />
       $sep = ", ";<br />
     }<br />
+<br />
+mysql_close();<br />
+<br />
     $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $message);<br />
     unset($sep);<br />
+<br />
+echo "LISTDEVICES\n";<br />
+<br />
   }<br />
 }</p>
<p>@@ -62,6 +164,8 @@<br />
 $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!listdevices', $bot, 'list_devices');<br />
 $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!device', $bot, 'device_info');<br />
 $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!port', $bot, 'port_info');<br />
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!down', $bot, 'down_info');<br />
+$irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '!version', $bot, 'version_info');</p>
<p> $irc->connect($config['irc_host'], $config['irc_port']);<br />
 $irc->login($config['irc_nick'], 'Observium Bot', 0, $config['irc_nick']);<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.kulish.com/2011/05/14/irc-diff-05142011-txt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MariaDB</title>
		<link>http://tech.kulish.com/2010/08/25/183/</link>
		<comments>http://tech.kulish.com/2010/08/25/183/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 00:22:46 +0000</pubDate>
		<dc:creator>Null</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MariaDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://tech.kulish.com/?p=183</guid>
		<description><![CDATA[We have upgraded the websites and email servers from MySQL to MariaDB. Currently researching changes in tuning, if any.]]></description>
			<content:encoded><![CDATA[<p>We have upgraded the websites and email servers from MySQL to MariaDB.</p>
<p>Currently researching changes in tuning, if any.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.kulish.com/2010/08/25/183/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TECH.kulish.com Migration</title>
		<link>http://tech.kulish.com/2010/07/24/tech-kulish-com-migration/</link>
		<comments>http://tech.kulish.com/2010/07/24/tech-kulish-com-migration/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 16:44:26 +0000</pubDate>
		<dc:creator>Null</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[kulish]]></category>

		<guid isPermaLink="false">http://tech.kulish.com/?p=162</guid>
		<description><![CDATA[As you may have noticed, the site has migrated from Drupal to WordPress. Please bear with us while we finish implementing all the features of the old site. Thank You.]]></description>
			<content:encoded><![CDATA[<p>As you may have noticed, the site has migrated from Drupal to WordPress.</p>
<p>Please bear with us while we finish implementing all the features of the old site.</p>
<p>Thank You.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.kulish.com/2010/07/24/tech-kulish-com-migration/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>6/08 Outage</title>
		<link>http://tech.kulish.com/2010/06/08/608-outage/</link>
		<comments>http://tech.kulish.com/2010/06/08/608-outage/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 16:02:47 +0000</pubDate>
		<dc:creator>Null</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[restore]]></category>
		<category><![CDATA[UPS]]></category>

		<guid isPermaLink="false">http://tech.lan.side/?p=33</guid>
		<description><![CDATA[Apparently we had a power failure today that my UPS wasn&#8217;t quick enough to take over for. Everything is back up and running. One database was corrupted but we were able restore it from this morning&#8217;s backup. Backups will be more frequent during storm season.]]></description>
			<content:encoded><![CDATA[<p>Apparently we had a power failure today that my UPS wasn&#8217;t quick enough to take over for.</p>
<p>Everything is back up and running.</p>
<p>One database was corrupted but we were able restore it from this morning&#8217;s backup.<br />
Backups will be more frequent during storm season.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.kulish.com/2010/06/08/608-outage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drupal Issue</title>
		<link>http://tech.kulish.com/2009/12/25/drupal-issue/</link>
		<comments>http://tech.kulish.com/2009/12/25/drupal-issue/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 11:59:56 +0000</pubDate>
		<dc:creator>Null</dc:creator>
				<category><![CDATA[Daemons]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[family]]></category>
		<category><![CDATA[kulish]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://tech.lan.side/?p=42</guid>
		<description><![CDATA[We are currently experiencing an issue with editing account information. The problem is being researched and status will be provided when information is available. The following sites are affected: http://tech.kulish.com http://family.kulish.com http://www.iowajeep.net http://www.racebus.org]]></description>
			<content:encoded><![CDATA[<p>We are currently experiencing an issue with editing account information.<br />
The problem is being researched and status will be provided when information is available.</p>
<p>The following sites are affected:</p>
<p>http://tech.kulish.com</p>
<p>http://family.kulish.com</p>
<p>http://www.iowajeep.net</p>
<p>http://www.racebus.org</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.kulish.com/2009/12/25/drupal-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>D4rk Theme Issues</title>
		<link>http://tech.kulish.com/2009/11/02/d4rk-theme-issues/</link>
		<comments>http://tech.kulish.com/2009/11/02/d4rk-theme-issues/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 10:31:58 +0000</pubDate>
		<dc:creator>Null</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Website]]></category>
		<category><![CDATA[CR]]></category>
		<category><![CDATA[FIXED]]></category>
		<category><![CDATA[Spacing Spacing]]></category>
		<category><![CDATA[Text Black]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://tech.lan.side/?p=44</guid>
		<description><![CDATA[New Drupal theme issues: (FIXED)1. Text &#8211; Links Too dark. The gray is a couple shades too dark for it&#8217;s background color. (FIXED)2. Text &#8211; Black text, in text entry areas, is too dark. (search box) (FIXED)3. Spacing &#8211; Spacing on articles and blocks. There needs to be a CR between the controls of an [...]]]></description>
			<content:encoded><![CDATA[<p>New Drupal theme issues:</p>
<p>(FIXED)1. Text &#8211; Links Too dark.  The gray is a couple shades too dark for it&#8217;s background color.</p>
<p>(FIXED)2. Text &#8211; Black text, in text entry areas, is too dark. (search box)</p>
<p>(FIXED)3. Spacing &#8211; Spacing on articles and blocks.<br />
    There needs to be a CR between the controls of an article teaser and the title of the next.<br />
    In blocks, there needs to be a CR at the end.</p>
<p>(MOSTLY)4. Preview &#8211; white text on white background.  Mostly fixed.  You can now see the body but some fields, like author, still have some white text on white background.  Comment preview works fine however.</p>
<p>(FIXED)5. Bottom AdSense block not showing properly. (Apparently main page only)</p>
<p>(FIXED)6. Pager black text too dark.</p>
<p><a href="http://www.cialug.org">CIALUG</a>, the local linux users group, suggested using firebug to find these issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.kulish.com/2009/11/02/d4rk-theme-issues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a MySQL Capable Postfix RPM</title>
		<link>http://tech.kulish.com/2009/10/18/building-a-mysql-capable-postfix-rpm/</link>
		<comments>http://tech.kulish.com/2009/10/18/building-a-mysql-capable-postfix-rpm/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 15:19:59 +0000</pubDate>
		<dc:creator>Null</dc:creator>
				<category><![CDATA[Daemons]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[smtp]]></category>
		<category><![CDATA[dovecot]]></category>
		<category><![CDATA[PGSQL]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[RPM]]></category>
		<category><![CDATA[RPMS]]></category>

		<guid isPermaLink="false">http://tech.lan.side/?p=45</guid>
		<description><![CDATA[Build Environment: CentOS 5 x86_64 Postfix 2.3.3 Sources gcc version 4.1.2 20080704 (Red Hat 4.1.2-44) 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux # Get the src 1) wget http://mirror.centos.org/centos/5.3/centosplus/SRPMS/postfix-2.3.3-2.1.centos.mysql_pgsql.src.rpm # Install the src RPM 2) rpm -i postfix-2.3.3-2.1.centos.mysql_pgsql.src.rpm # Install some dependencies I didn&#8217;t have 3.1) yum install pcre-devel [...]]]></description>
			<content:encoded><![CDATA[<p>Build Environment:<br />
CentOS 5 x86_64<br />
Postfix 2.3.3 Sources<br />
gcc version 4.1.2 20080704 (Red Hat 4.1.2-44)</p>
<p>2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux</p>
<p># Get the src<br />
1) wget http://mirror.centos.org/centos/5.3/centosplus/SRPMS/postfix-2.3.3-2.1.centos.mysql_pgsql.src.rpm</p>
<p># Install the src RPM<br />
2) rpm -i postfix-2.3.3-2.1.centos.mysql_pgsql.src.rpm</p>
<p># Install some dependencies I didn&#8217;t have<br />
3.1) yum install pcre-devel<br />
3.2) yum install rpm-build<br />
3.3) yum install mysql-devel.x86_64 openldap-devel.x86_64 db4-devel.x86_64<br />
3.4) yum install gcc.x86_64</p>
<p># Edit SPECS; remove postgres support<br />
4.1) cd /usr/src/redhat/SPECS<br />
4.2) vi postfix.spec and change &#8220;%%define PGSQL 1&#8243; to &#8220;%define PGSQL 0&#8243;<br />
     # I didn&#8217;t want Postgres support<br />
4.3) &#8220;%define MYSQL 1&#8243; was already defined for me</p>
<p># Build the new rpm<br />
5) rpmbuild -ba postfix.spec # Ignore warnings</p>
<p># Install the new rpm<br />
6.1) cd /usr/src/redhat/RPMS<br />
6.2) rpm -i postfix-2.3.3-2.1.centos.mysql_pgsql.x86_64.rpm</p>
<p>Building an RPM build environment: <a href="http://wiki.centos.org/HowTos/SetupRpmBuildEnvironment">CentOS Wiki</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tech.kulish.com/2009/10/18/building-a-mysql-capable-postfix-rpm/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simple MySQL Backup Script</title>
		<link>http://tech.kulish.com/2005/12/15/simple-mysql-backup-script/</link>
		<comments>http://tech.kulish.com/2005/12/15/simple-mysql-backup-script/#comments</comments>
		<pubDate>Thu, 15 Dec 2005 05:00:36 +0000</pubDate>
		<dc:creator>Null</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[OS]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[Backup Script]]></category>
		<category><![CDATA[BSD]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://tech.lan.side/?p=109</guid>
		<description><![CDATA[Below is a simple database backup script to use with MySQL. #!/usr/bin/perl -w use strict; # Backup &#8211; Script used to backup MySQL databases to an NFS share. # VERSION: 1.2 # DATE: 12152005 # AUTHOR: packetmad # This is a Freebsd 4.x-centric script. It may run on other # versions of Freebsd, or any [...]]]></description>
			<content:encoded><![CDATA[<p>Below is a simple database backup script to use with MySQL.</p>
<p>#!/usr/bin/perl -w</p>
<p>use strict;</p>
<p># Backup &#8211; Script used to backup MySQL databases to an NFS share.<br />
# VERSION: 1.2<br />
# DATE: 12152005<br />
# AUTHOR: packetmad</p>
<p># This is a Freebsd 4.x-centric script. It may run on other<br />
# versions of Freebsd, or any other BSD for that matter, but I<br />
# wrote it on a Freebsd 4.7 system. It&#8217;s not even guaranteed<br />
# to run on that.</p>
<p># Speaking of guarantees, warranties, etc., there ain&#8217;t one, so<br />
# don&#8217;t even try. :P<br />
# I am not responsible for the output of this script, nor am I<br />
# responsible for any damage or data loss as a result of using<br />
# this script. In short, I am not responsible for anything<br />
# regarding this script.<br />
# Furthermore, I am not responsible if this script causes<br />
# Your dog to die, your wife to leave you, or<br />
# your truck to break down.<br />
# I am releasing this script under the conventions of the BSD<br />
# license. You can use it, modify it, sleep with it, or<br />
# whatever. If you do find this script useful or have<br />
# suggestions on a better way to do some things contained here<br />
# in, I welcome all correspondence.<br />
# The latest version of this script can be obtained at:<br />
# http://tech.kulish.com</p>
<p># USE THIS SCRIPT AT YOUR OWN RISK!!!!!!!!!!!!!!!!!!</p>
<p># Change Log<br />
# v1.1<br />
# Date: 11302002<br />
# Initial Release, absolutely BUG FREE! :)<br />
# v1.2<br />
# Date: 12152005<br />
# Added compression functionality<br />
# Added naming of backup files by date<br />
# Changed longterm storeage directory for 1back to store1</p>
<p>###<br />
# Declare variables and arrays.<br />
###</p>
<p>my (<br />
$bdir, $sysname, $logfile, %databases, $key, $database, $rightnow<br />
);</p>
<p>$bdir = &#8216;/databases/&#8217;;<br />
chomp ( $sysname = `uname -n` );<br />
chomp ( $rightnow = `date +%m%d%G%H%M` );<br />
#print $rightnow;<br />
# Databases we want to backup and associated archive names.<br />
# Database => sql file pairs.</p>
<p>%databases = (&#8216;testdb1&#8242; => &#8216;testdb1.sql&#8217;,<br />
&#8216;testdb2&#8242; => &#8216;testdb2.sql&#8217;);</p>
<p>###<br />
# Backup Section<br />
###<br />
foreach $key (sort keys %databases) {<br />
$database = $databases{$key};<br />
`mysqldump -uUSERNAME -pPASSWORD $key >> $bdir$sysname/$database`;}</p>
<p>###<br />
# Compression Functionality<br />
###</p>
<p>foreach $key (sort keys %databases) {<br />
$database = $databases{$key};<br />
`gzip -c $bdir$sysname/$database > $bdir$sysname/$rightnow$database.gz`;}</p>
<p># scp them to the fileshare<br />
#`scp $bdir$sysname/*.gz USERNAME\@SERVER:databases`;</p>
<p>###<br />
# Clean backup dir<br />
###</p>
<p>`rm -rf $bdir$sysname/*.sql`;<br />
`mv $bdir$sysname/*.gz $bdir$sysname/store1`;</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.kulish.com/2005/12/15/simple-mysql-backup-script/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: kulish.com @ 2012-02-07 19:04:47 by W3 Total Cache -->
