<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="fr">
	<id>https://wiki.sn4ky.net/index.php?action=history&amp;feed=atom&amp;title=MySQL</id>
	<title>MySQL - Historique des versions</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sn4ky.net/index.php?action=history&amp;feed=atom&amp;title=MySQL"/>
	<link rel="alternate" type="text/html" href="https://wiki.sn4ky.net/index.php?title=MySQL&amp;action=history"/>
	<updated>2026-05-06T13:12:03Z</updated>
	<subtitle>Historique des versions pour cette page sur le wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://wiki.sn4ky.net/index.php?title=MySQL&amp;diff=16&amp;oldid=prev</id>
		<title>Sn4kY : Page créée avec « = MySQL Multi Master = MySQL 5.5 Master/Master  http://huyphongnguyen.wordpress.com/2013/04/18/installation-mysql-5-5-et-replication-master-master/  = Debug = == [ERROR] E... »</title>
		<link rel="alternate" type="text/html" href="https://wiki.sn4ky.net/index.php?title=MySQL&amp;diff=16&amp;oldid=prev"/>
		<updated>2018-04-12T14:00:11Z</updated>

		<summary type="html">&lt;p&gt;Page créée avec « = MySQL Multi Master = MySQL 5.5 Master/Master  http://huyphongnguyen.wordpress.com/2013/04/18/installation-mysql-5-5-et-replication-master-master/  = Debug = == [ERROR] E... »&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Nouvelle page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= MySQL Multi Master =&lt;br /&gt;
MySQL 5.5 Master/Master &lt;br /&gt;
http://huyphongnguyen.wordpress.com/2013/04/18/installation-mysql-5-5-et-replication-master-master/&lt;br /&gt;
&lt;br /&gt;
= Debug =&lt;br /&gt;
== [ERROR] Error in accept: Too many open files ==&lt;br /&gt;
== ERROR 1018 (HY000): Can&amp;#039;t read dir of &amp;#039;.&amp;#039; (errno: 24) ==&lt;br /&gt;
Ces deux erreurs sont liées. La première donne une explication.&lt;br /&gt;
&lt;br /&gt;
Il faut modifier la valeur de ulimit, et mettre un paramètre dans la config mysql : open-files-limit = xxx&lt;br /&gt;
= Script pour extraite une table d&amp;#039;un dump SQL complet =&lt;br /&gt;
[http://webftp.sn4ky.net/scripts/extract_sql.pl Télécharger le script]&lt;br /&gt;
&lt;br /&gt;
source http://blog.tsheets.com/2008/tips-tricks/extract-a-single-table-from-a-mysqldump-file.html&lt;br /&gt;
 #!/usr/bin/perl -w&lt;br /&gt;
 ##############################################################################&lt;br /&gt;
 ##  &lt;br /&gt;
 ##  Written by: Jared Cheney &amp;lt;jared.cheney@gmail.com&amp;gt;&lt;br /&gt;
 ##&lt;br /&gt;
 ##  Original Template written by: &lt;br /&gt;
 ##     Brandon Zehm &amp;lt;caspian@dotconf.net&amp;gt; and Jared Cheney &amp;lt;elph@leph.net&amp;gt;&lt;br /&gt;
 ##  &lt;br /&gt;
 ##  License:&lt;br /&gt;
 ##  &lt;br /&gt;
 ##  This &amp;lt;programName&amp;gt; (hereafter referred to as &amp;quot;program&amp;quot;) is free software;&lt;br /&gt;
 ##    you can redistribute it and/or modify it under the terms of the GNU General&lt;br /&gt;
 ##    Public License as published by the Free Software Foundation; either version&lt;br /&gt;
 ##    2 of the License, or (at your option) any later version.&lt;br /&gt;
 ##  Note that when redistributing modified versions of this source code, you&lt;br /&gt;
 ##    must ensure that this disclaimer and the above coder&amp;#039;s names are included&lt;br /&gt;
 ##    VERBATIM in the modified code.&lt;br /&gt;
 ##  &lt;br /&gt;
 ##  Disclaimer:&lt;br /&gt;
 ##    This program is provided with no warranty of any kind, either expressed or&lt;br /&gt;
 ##    implied.  It is the responsibility of the user (you) to fully research and&lt;br /&gt;
 ##    comprehend the usage of this program.  As with any tool, it can be misused,&lt;br /&gt;
 ##    either intentionally (you&amp;#039;re a vandal) or unintentionally (you&amp;#039;re a moron).&lt;br /&gt;
 ##    THE AUTHOR(S) IS(ARE) NOT RESPONSIBLE FOR ANYTHING YOU DO WITH THIS PROGRAM&lt;br /&gt;
 ##    or anything that happens because of your use (or misuse) of this program,&lt;br /&gt;
 ##    including but not limited to anything you, your lawyers, or anyone else&lt;br /&gt;
 ##    can dream up.  And now, a relevant quote directly from the GPL:&lt;br /&gt;
 ##    &lt;br /&gt;
 ##    NO WARRANTY&lt;br /&gt;
 ##    &lt;br /&gt;
 ##    11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY&lt;br /&gt;
 ##    FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN&lt;br /&gt;
 ##    OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES&lt;br /&gt;
 ##    PROVIDE THE PROGRAM &amp;quot;AS IS&amp;quot; WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED&lt;br /&gt;
 ##    OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF&lt;br /&gt;
 ##    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS&lt;br /&gt;
 ##    TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE&lt;br /&gt;
 ##    PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,&lt;br /&gt;
 ##    REPAIR OR CORRECTION.&lt;br /&gt;
 ##    &lt;br /&gt;
 ##############################################################################&lt;br /&gt;
 # Written by: Jared Cheney &amp;lt;jared.cheney@gmail.com&amp;gt;&lt;br /&gt;
 #&lt;br /&gt;
 # Purpose:  This program will extract the necessary portions from a full &lt;br /&gt;
 #           database mysqldump file required to restore a single table.&lt;br /&gt;
 #&lt;br /&gt;
 # Creation Date: 2008-05-23&lt;br /&gt;
 #&lt;br /&gt;
 # Changelog:&lt;br /&gt;
 #  2008-05-23  v1.0  Jared Cheney&lt;br /&gt;
 #   - initial release&lt;br /&gt;
 #&lt;br /&gt;
 #############################################################################&lt;br /&gt;
 &lt;br /&gt;
 ## FIXME&amp;#039;s:&lt;br /&gt;
 &lt;br /&gt;
 use strict;&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 ## Global Variable(s)&lt;br /&gt;
 my %conf = (&lt;br /&gt;
     &amp;quot;programName&amp;quot;          =&amp;gt; $0,                                ## The name of this program&lt;br /&gt;
     &amp;quot;version&amp;quot;              =&amp;gt; &amp;#039;1.0&amp;#039;,                             ## The version of this program&lt;br /&gt;
     &amp;quot;authorName&amp;quot;           =&amp;gt; &amp;#039;Jared Cheney&amp;#039;,                    ## Author&amp;#039;s Name&lt;br /&gt;
     &amp;quot;authorEmail&amp;quot;          =&amp;gt; &amp;#039;jared.cheney@gmail.com&amp;#039;,          ## Author&amp;#039;s Email Address&lt;br /&gt;
     &amp;quot;debug&amp;quot;                =&amp;gt; 0,                                 ## Default debug level&lt;br /&gt;
     &amp;quot;mode&amp;quot;                 =&amp;gt; &amp;#039;&amp;#039;,&lt;br /&gt;
     &lt;br /&gt;
 &lt;br /&gt;
     ## PROGRAM VARIABLES&lt;br /&gt;
     &amp;quot;logFile&amp;quot;              =&amp;gt; &amp;#039;&amp;#039;,                                ## default log file, if none specified on command line&lt;br /&gt;
     &amp;quot;prepend&amp;quot;              =&amp;gt; &amp;#039;&amp;#039;,                                ## Something that gets added to every msg that the script outputs&lt;br /&gt;
     &amp;quot;alertCommand&amp;quot;         =&amp;gt; &amp;#039;&amp;#039;,                                ## cmd to run if printmsg() contains the string &amp;#039;ERR&amp;#039; or &amp;#039;CRIT&amp;#039; or &amp;#039;WARN&amp;#039;&lt;br /&gt;
     &amp;quot;noExtras&amp;quot;             =&amp;gt; 0,                                 ## if 1, then we&amp;#039;ll skip extra cmds for disabling foreign key checks, etc. at top of file&lt;br /&gt;
     &amp;quot;listTables&amp;quot;           =&amp;gt; 0,                                 ## if 1, then return a list of tables contained in the restore file&lt;br /&gt;
 );&lt;br /&gt;
 &lt;br /&gt;
 $conf{&amp;#039;programName&amp;#039;} =~ s/(.)*[\/,\\]//;                         ## Remove path from filename&lt;br /&gt;
 $0 = &amp;quot;[$conf{&amp;#039;programName&amp;#039;}]&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 #############################&lt;br /&gt;
 ##&lt;br /&gt;
 ##      MAIN PROGRAM&lt;br /&gt;
 ##&lt;br /&gt;
 #############################&lt;br /&gt;
 &lt;br /&gt;
 ## Initialize&lt;br /&gt;
 initialize();&lt;br /&gt;
 &lt;br /&gt;
 ## Process Command Line&lt;br /&gt;
 processCommandLine();&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 ## get current timestamp for use later&lt;br /&gt;
 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();&lt;br /&gt;
 $mon +=1;&lt;br /&gt;
 if ($mon &amp;lt; 10) {$mon = &amp;quot;0&amp;quot; . $mon}&lt;br /&gt;
 if ($mday &amp;lt; 10) {$mday = &amp;quot;0&amp;quot; . $mday}&lt;br /&gt;
 $year +=1900;&lt;br /&gt;
 printmsg (&amp;quot;current date is $mon/$mday/$year&amp;quot;,3);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 if ($conf{&amp;#039;mode&amp;#039;} eq &amp;quot;running&amp;quot;) {&lt;br /&gt;
     printmsg (&amp;quot;INFO =&amp;gt; PROGRAM STARTED&amp;quot;,1);&lt;br /&gt;
 &lt;br /&gt;
     #############################&lt;br /&gt;
     ########    MAIN CODE    ####&lt;br /&gt;
     #############################&lt;br /&gt;
     &lt;br /&gt;
     if ($conf{&amp;#039;restoreFile&amp;#039;}) {&lt;br /&gt;
         ## open the mysqldump file&lt;br /&gt;
         open(STDIN, &amp;quot;&amp;lt;$conf{&amp;#039;restoreFile&amp;#039;}&amp;quot;) || quit(&amp;quot;ERROR =&amp;gt; Couldn&amp;#039;t open file $conf{&amp;#039;restoreFile&amp;#039;}: $!&amp;quot;, 3);&lt;br /&gt;
     }&lt;br /&gt;
     &lt;br /&gt;
     my $flag = 0;&lt;br /&gt;
     &lt;br /&gt;
     ## go through the file one line at a time&lt;br /&gt;
     while (my $line = &amp;lt;STDIN&amp;gt;) {&lt;br /&gt;
         &lt;br /&gt;
         if ($conf{&amp;#039;listTables&amp;#039;}) {&lt;br /&gt;
             if ($line =~ /^-- Table structure for table `(.*)`/) {&lt;br /&gt;
                 print $1 . &amp;quot;\n&amp;quot;;&lt;br /&gt;
             }&lt;br /&gt;
         }&lt;br /&gt;
         else {&lt;br /&gt;
         &lt;br /&gt;
             ## if we&amp;#039;re not ignoring extra lines, and we haven&amp;#039;t set the flag, and if it&amp;#039;s not a 40000 code, then print&lt;br /&gt;
             if (!$conf{&amp;#039;noExtras&amp;#039;} &amp;amp;&amp;amp; !$flag) {&lt;br /&gt;
                 if ($line =~ /^\/\*!(.....).*\*\//) { print $line unless ($1 == 40000); }&lt;br /&gt;
             }&lt;br /&gt;
             &lt;br /&gt;
             ## set a flag when we encounter the table we want&lt;br /&gt;
             if ($line =~ /^-- Table structure for table `$conf{&amp;#039;tableName&amp;#039;}`/) {&lt;br /&gt;
                 $flag = 1;&lt;br /&gt;
                 printmsg(&amp;quot;Turning flag on&amp;quot;, 1);&lt;br /&gt;
             }&lt;br /&gt;
             ## turn flag off as soon as we encounter next table definition&lt;br /&gt;
             elsif ($line =~ /^-- Table structure for table/) {&lt;br /&gt;
                 $flag = 0;&lt;br /&gt;
                 printmsg(&amp;quot;Turning flag off&amp;quot;, 1);&lt;br /&gt;
             }&lt;br /&gt;
             &lt;br /&gt;
             ## if flag is set, then print to STDOUT, otherwise just move on&lt;br /&gt;
             if ($flag) {&lt;br /&gt;
                 print $line;&lt;br /&gt;
             }&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
     &lt;br /&gt;
     &lt;br /&gt;
     &lt;br /&gt;
     &lt;br /&gt;
     &lt;br /&gt;
     &lt;br /&gt;
     &lt;br /&gt;
     #############################&lt;br /&gt;
     ########  END MAIN CODE  ####&lt;br /&gt;
     #############################&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 ## Quit&lt;br /&gt;
 quit(&amp;quot;&amp;quot;,0);&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 ######################################################################&lt;br /&gt;
 ## Function:    help ()&lt;br /&gt;
 ##&lt;br /&gt;
 ## Description: For all those newbies ;) &lt;br /&gt;
 ##              Prints a help message and exits the program.&lt;br /&gt;
 ## &lt;br /&gt;
 ######################################################################&lt;br /&gt;
 sub help {&lt;br /&gt;
 print &amp;lt;&amp;lt;EOM;&lt;br /&gt;
 &lt;br /&gt;
 $conf{&amp;#039;programName&amp;#039;}-$conf{&amp;#039;version&amp;#039;} by $conf{&amp;#039;authorName&amp;#039;} &amp;lt;$conf{&amp;#039;authorEmail&amp;#039;}&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 This program will parse a full mysqldump file and &lt;br /&gt;
 extract the necessary portions required to restore &lt;br /&gt;
 a single table.  The output is printed to STDOUT, so you&amp;#039;ll&lt;br /&gt;
 want to redirect to a file from the command line, like so:&lt;br /&gt;
 $conf{&amp;#039;programName&amp;#039;} &amp;gt; somefile.sql&lt;br /&gt;
 &lt;br /&gt;
 Brought to you by the fine tech folk at www.tsheets.com - Time Is Money, Track It!&lt;br /&gt;
 &lt;br /&gt;
 Usage:  $conf{&amp;#039;programName&amp;#039;} -t _table_name_ -r _restore_file_ [options]&lt;br /&gt;
   &lt;br /&gt;
   Required:&lt;br /&gt;
     -t _table_name_       table name to extract from the file&lt;br /&gt;
     &lt;br /&gt;
     &lt;br /&gt;
   Optional:&lt;br /&gt;
     -r _restore_file_     mysqldump file that you want to parse. If not specified, &lt;br /&gt;
                           then it reads from STDIN&lt;br /&gt;
     --listTables          If set, then a list of tables existing in your restore file is returned,&lt;br /&gt;
                           and no other actions are taken&lt;br /&gt;
     --noExtras            If set, then extra cmds at top of mysqldump file&lt;br /&gt;
                           will not be included (such as disabling foreign key checks).&lt;br /&gt;
                           Usually you will want these things changed before restoring a&lt;br /&gt;
                           table, so the default is for these to be included.&lt;br /&gt;
     -v                    verbosity - use multiple times for greater effect&lt;br /&gt;
     -h                    Display this help message&lt;br /&gt;
 &lt;br /&gt;
                                                                &lt;br /&gt;
   &lt;br /&gt;
 EOM&lt;br /&gt;
 exit(1);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 ######################################################################&lt;br /&gt;
 ##  Function: initialize ()&lt;br /&gt;
 ##  &lt;br /&gt;
 ##  Does all the script startup jibberish.&lt;br /&gt;
 ##  &lt;br /&gt;
 ######################################################################&lt;br /&gt;
 sub initialize {&lt;br /&gt;
 &lt;br /&gt;
   ## Set STDOUT to flush immediatly after each print  &lt;br /&gt;
   $| = 1;&lt;br /&gt;
 &lt;br /&gt;
   ## Intercept signals&lt;br /&gt;
   $SIG{&amp;#039;QUIT&amp;#039;}  = sub { quit(&amp;quot;$$ - $conf{&amp;#039;programName&amp;#039;} - EXITING: Received SIG$_[0]&amp;quot;, 1); };&lt;br /&gt;
   $SIG{&amp;#039;INT&amp;#039;}   = sub { quit(&amp;quot;$$ - $conf{&amp;#039;programName&amp;#039;} - EXITING: Received SIG$_[0]&amp;quot;, 1); };&lt;br /&gt;
   $SIG{&amp;#039;KILL&amp;#039;}  = sub { quit(&amp;quot;$$ - $conf{&amp;#039;programName&amp;#039;} - EXITING: Received SIG$_[0]&amp;quot;, 1); };&lt;br /&gt;
   $SIG{&amp;#039;TERM&amp;#039;}  = sub { quit(&amp;quot;$$ - $conf{&amp;#039;programName&amp;#039;} - EXITING: Received SIG$_[0]&amp;quot;, 1); };&lt;br /&gt;
   &lt;br /&gt;
   ## ALARM and HUP signals are not supported in Win32&lt;br /&gt;
   unless ($^O =~ /win/i) {&lt;br /&gt;
       $SIG{&amp;#039;HUP&amp;#039;}   = sub { quit(&amp;quot;$$ - $conf{&amp;#039;programName&amp;#039;} - EXITING: Received SIG$_[0]&amp;quot;, 1); };&lt;br /&gt;
       $SIG{&amp;#039;ALRM&amp;#039;}  = sub { quit(&amp;quot;$$ - $conf{&amp;#039;programName&amp;#039;} - EXITING: Received SIG$_[0]&amp;quot;, 1); };&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   return(1);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 ######################################################################&lt;br /&gt;
 ##  Function: processCommandLine ()&lt;br /&gt;
 ##  &lt;br /&gt;
 ##  Processes command line storing important data in global var %conf&lt;br /&gt;
 ##  &lt;br /&gt;
 ######################################################################&lt;br /&gt;
 sub processCommandLine {&lt;br /&gt;
     &lt;br /&gt;
     &lt;br /&gt;
     ############################&lt;br /&gt;
     ##  Process command line  ##&lt;br /&gt;
     ############################&lt;br /&gt;
     &lt;br /&gt;
     my $x;&lt;br /&gt;
     my @ARGS = @ARGV;&lt;br /&gt;
     my $numargv = scalar(@ARGS);&lt;br /&gt;
     help() unless ($numargv);&lt;br /&gt;
     for (my $i = 0; $i &amp;lt; $numargv; $i++) {&lt;br /&gt;
         $x = $ARGS[$i];&lt;br /&gt;
         if    ($x =~ /^-h$|^--help$/)   { help(); }&lt;br /&gt;
         elsif ($x =~ /^-v+/i)           { my $tmp = (length($&amp;amp;) - 1); $conf{&amp;#039;debug&amp;#039;} += $tmp; }&lt;br /&gt;
         elsif ($x =~ /^-l$/)            { $i++; $conf{&amp;#039;logFile&amp;#039;}    = $ARGS[$i];}&lt;br /&gt;
         elsif ($x =~ /^-p$/)            { $i++; $conf{&amp;#039;policyName&amp;#039;} = $ARGS[$i];}&lt;br /&gt;
         elsif ($x =~ /^-t$/)            { $i++; $conf{&amp;#039;tableName&amp;#039;}  = $ARGS[$i];}&lt;br /&gt;
         elsif ($x =~ /^-r$/)            { $i++; $conf{&amp;#039;restoreFile&amp;#039;}= $ARGS[$i];}&lt;br /&gt;
         elsif ($x =~ /^--noExtras$/i)   {       $conf{&amp;#039;noExtras&amp;#039;}   = 1;        }&lt;br /&gt;
         elsif ($x =~ /^--listTables$/i) {       $conf{&amp;#039;listTables&amp;#039;} = 1;        }&lt;br /&gt;
         else  { &lt;br /&gt;
             printmsg(&amp;quot;Error: \&amp;quot;$x\&amp;quot; is not a recognised option!&amp;quot;, 0);&lt;br /&gt;
             help(); &lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
     &lt;br /&gt;
     my @required = (&lt;br /&gt;
                       &amp;#039;tableName&amp;#039;,&lt;br /&gt;
     );&lt;br /&gt;
     &lt;br /&gt;
     if ($conf{&amp;#039;listTables&amp;#039;}) {&lt;br /&gt;
         $conf{&amp;#039;mode&amp;#039;} = &amp;#039;running&amp;#039;;&lt;br /&gt;
         return(1);&lt;br /&gt;
     }&lt;br /&gt;
     &lt;br /&gt;
     foreach (@required) {&lt;br /&gt;
         if (!$conf{$_}) {&lt;br /&gt;
             quit(&amp;quot;ERROR: Value [$_] was not set after parsing command line arguments!&amp;quot;, 1);&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
     $conf{&amp;#039;mode&amp;#039;} = &amp;#039;running&amp;#039;;&lt;br /&gt;
     return(1);&lt;br /&gt;
 }&lt;br /&gt;
  &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 ###############################################################################################&lt;br /&gt;
 ##  Function:    printmsg (string $message, int $level)&lt;br /&gt;
 ##&lt;br /&gt;
 ##  Description: Handles all messages - logging them to a log file, &lt;br /&gt;
 ##               printing them to the screen or both depending on&lt;br /&gt;
 ##               the $level passed in, $conf{&amp;#039;debug&amp;#039;} and wether&lt;br /&gt;
 ##               $conf{&amp;#039;mode&amp;#039;}.&lt;br /&gt;
 ##&lt;br /&gt;
 ##  Input:       $message                A message to be printed, logged, etc.&lt;br /&gt;
 ##               $level                  The debug level of the message. If&lt;br /&gt;
 ##                                       not defined 0 will be assumed.  0 is&lt;br /&gt;
 ##                                       considered a normal message, 1 and &lt;br /&gt;
 ##                                       higher is considered a debug message.&lt;br /&gt;
 ##               $leaveCarriageReturn    Whether or not to strip carriage returns (always will strip, unless other than 0)&lt;br /&gt;
 ##  &lt;br /&gt;
 ##  Output:      Prints to STDOUT, to LOGFILE, both, or none depending &lt;br /&gt;
 ##               on the state of the program.&lt;br /&gt;
 ##  &lt;br /&gt;
 ##  Example:     printmsg (&amp;quot;WARNING: We believe in generic error messages... NOT!&amp;quot;, 1);&lt;br /&gt;
 ###############################################################################################&lt;br /&gt;
 sub printmsg {&lt;br /&gt;
     my %incoming = ();&lt;br /&gt;
     (&lt;br /&gt;
         $incoming{&amp;#039;message&amp;#039;},&lt;br /&gt;
         $incoming{&amp;#039;level&amp;#039;},&lt;br /&gt;
         $incoming{&amp;#039;leaveCarriageReturn&amp;#039;},&lt;br /&gt;
     ) = @_;&lt;br /&gt;
     $incoming{&amp;#039;level&amp;#039;} = 0 if (!defined($incoming{&amp;#039;level&amp;#039;}));&lt;br /&gt;
     $incoming{&amp;#039;leaveCarriageReturn&amp;#039;} = 0 if (!defined($incoming{&amp;#039;leaveCarriageReturn&amp;#039;}));&lt;br /&gt;
     $incoming{&amp;#039;message&amp;#039;} =~ s/\r|\n/ /sg unless ($incoming{&amp;#039;leaveCarriageReturn&amp;#039;} &amp;gt;= 1);&lt;br /&gt;
 &lt;br /&gt;
     ## Add program name and PID&lt;br /&gt;
     ## $incoming{&amp;#039;message&amp;#039;} = &amp;quot;- $conf{&amp;#039;programName&amp;#039;} [$$]: &amp;quot; . $incoming{&amp;#039;message&amp;#039;};&lt;br /&gt;
     ## add prepend info&lt;br /&gt;
     ## $incoming{&amp;#039;message&amp;#039;} = &amp;quot;$conf{&amp;#039;prepend&amp;#039;} : $incoming{&amp;#039;message&amp;#039;}&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
     ## Continue on if the debug level is &amp;gt;= the incoming message level&lt;br /&gt;
     if ($conf{&amp;#039;debug&amp;#039;} &amp;gt;= $incoming{&amp;#039;level&amp;#039;}) {&lt;br /&gt;
        ## Print to the log file&lt;br /&gt;
         if ($conf{&amp;#039;logFile&amp;#039;}) {&lt;br /&gt;
             open (LOGFILE, &amp;quot;&amp;gt;&amp;gt;$conf{&amp;#039;logFile&amp;#039;}&amp;quot;);&lt;br /&gt;
             print LOGFILE &amp;quot;$conf{&amp;#039;programName&amp;#039;}:[&amp;quot;. localtime() . &amp;quot;] $incoming{&amp;#039;message&amp;#039;}\n&amp;quot;;&lt;br /&gt;
             close (LOGFILE);&lt;br /&gt;
         }&lt;br /&gt;
         if ($conf{&amp;#039;alertCommand&amp;#039;} &amp;amp;&amp;amp; ($conf{&amp;#039;debug&amp;#039;} == 0) &amp;amp;&amp;amp; ($incoming{&amp;#039;message&amp;#039;} =~ /ERR|CRIT|WARN/) ) {&lt;br /&gt;
             my $tmpAlert = $conf{&amp;#039;alertCommand&amp;#039;};&lt;br /&gt;
             $tmpAlert =~ s/MESSAGE/$incoming{&amp;#039;message&amp;#039;}/g;&lt;br /&gt;
             system ($tmpAlert);&lt;br /&gt;
         }&lt;br /&gt;
         ## Print to STDOUT&lt;br /&gt;
         if ($conf{&amp;#039;debug&amp;#039;} &amp;gt;= 1) {&lt;br /&gt;
             print STDOUT &amp;quot;$conf{&amp;#039;programName&amp;#039;}:[&amp;quot; . localtime() . &amp;quot;]($incoming{&amp;#039;level&amp;#039;}): $incoming{&amp;#039;message&amp;#039;}\n&amp;quot;;&lt;br /&gt;
         }&lt;br /&gt;
         else {&lt;br /&gt;
             print STDOUT &amp;quot;$conf{&amp;#039;programName&amp;#039;}:[&amp;quot; . localtime() . &amp;quot;] $incoming{&amp;#039;message&amp;#039;}\n&amp;quot;;&lt;br /&gt;
         }&lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
     ## Return&lt;br /&gt;
     return(0);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 ######################################################################&lt;br /&gt;
 ##  Function:    quit (string $message, int $errorLevel)&lt;br /&gt;
 ##  &lt;br /&gt;
 ##  Description: Exits the program, optionally printing $message.  It &lt;br /&gt;
 ##               returns an exit error level of $errorLevel to the &lt;br /&gt;
 ##               system  (0 means no errors, and is assumed if empty.)&lt;br /&gt;
 ##&lt;br /&gt;
 ##  Example:     quit(&amp;quot;Exiting program normally&amp;quot;, 0);&lt;br /&gt;
 ######################################################################&lt;br /&gt;
 sub quit {&lt;br /&gt;
   my %incoming = ();&lt;br /&gt;
   (&lt;br /&gt;
     $incoming{&amp;#039;message&amp;#039;},&lt;br /&gt;
     $incoming{&amp;#039;errorLevel&amp;#039;}&lt;br /&gt;
   ) = @_;&lt;br /&gt;
   &lt;br /&gt;
   &lt;br /&gt;
   $incoming{&amp;#039;errorLevel&amp;#039;} = 0 if (!defined($incoming{&amp;#039;errorLevel&amp;#039;}));&lt;br /&gt;
   &lt;br /&gt;
   ## Print exit message&lt;br /&gt;
   if ($incoming{&amp;#039;message&amp;#039;}) { &lt;br /&gt;
       printmsg($incoming{&amp;#039;message&amp;#039;}, 0);&lt;br /&gt;
   }&lt;br /&gt;
   &lt;br /&gt;
   ## Exit&lt;br /&gt;
   exit($incoming{&amp;#039;errorLevel&amp;#039;});&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Sn4kY</name></author>
	</entry>
</feed>