<?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
    <title>Posteet: log</title> 
    <link>http://www.posteet.com/</link> 
    <description>Recent posteets posted to Posteet</description>
    <ttl>60</ttl>

    
    <item>
        <title>Script bash pour logger le résultat d'une commande wget</title>
        <link>http://www.posteet.com/view/1371</link>
        <description>
        <![CDATA[<pre>wget http://exemple.com/index.php &gt;result.txt 2&gt;result.txt
FICHIER=`sed '/^$/d' result.txt | head -1 | cut -d&quot; &quot; -f2-20`
RETOUR=`sed '/^$/d' result.txt | tail -1`
DATEHEURE=`date &quot;+%Y-%m-%d %H:%m:%S&quot;`
touch flux.log
echo &quot;$DATEHEURE -$FICHIER : $RETOUR&quot; &gt;&gt;flux.log</pre> <a href="http://www.posteet.com/tags/bash">[bash]</a>  <a href="http://www.posteet.com/tags/log">[log]</a>  <a href="http://www.posteet.com/tags/wget">[wget]</a> ]]>        </description>
        <dc:creator>cyo</dc:creator>
        <pubDate>Wed, 26 Nov 2008 11:28:34 +0000</pubDate>

            <category>bash</category>
            <category>log</category>
            <category>wget</category>
    
    </item>

  
    <item>
        <title>Monitor a log file and execute commands based on patterns</title>
        <link>http://www.posteet.com/view/1311</link>
        <description>
        <![CDATA[<pre>#!/bin/sh
tail -fn0 /var/log/file.log | while read line ; do
        echo &quot;$line&quot; | grep &quot;pattern&quot;
        if [ $? = 0 ]
        then
                # Actions
                echo &quot;Yeah: $line&quot;
        fi
done</pre> <a href="http://www.posteet.com/tags/bash">[bash]</a>  <a href="http://www.posteet.com/tags/log">[log]</a>  <a href="http://www.posteet.com/tags/shell">[shell]</a>  <a href="http://www.posteet.com/tags/tail">[tail]</a>  <a href="http://www.posteet.com/tags/while">[while]</a> ]]>        </description>
        <dc:creator>spirit</dc:creator>
        <pubDate>Fri, 10 Oct 2008 13:42:42 +0000</pubDate>

            <category>bash</category>
            <category>log</category>
            <category>shell</category>
            <category>tail</category>
            <category>while</category>
    
    </item>

  
    <item>
        <title>onlogdo - monitor a log file and execute commands based on patterns</title>
        <link>http://www.posteet.com/view/1309</link>
        <description>
        <![CDATA[<pre>#!/bin/bash

# Author: Ben Wong &lt;ben@wongs.net&gt;
# Created on: &lt;2001-08-08 11:56:03 hackerb9&gt;
# Time-stamp: &lt;2002-11-20 14:13:11 bbb&gt;

# onlogdo: a hack to handle a common problem: when a certain message
# shows up in the log file, an action should be performed. E.g.: when
# a PC-card network device is inserted, it should be ifconfig'd or
# perhaps dhclient should be run. This program can do that in a fairly
# reasonable way.



### FIRST, THE HELPER FUNCTIONS ###

function showmanpage () {
    cat &lt;&lt;'EOF'
NAME

   onlogdo - monitor a log file and execute commands based on patterns


SYNOPSIS

   onlogdo &lt;logfile&gt; &lt;pattern&gt; &lt;command&gt; [ &lt;pattern&gt; &lt;command&gt; ... ]

     logfile: a file that gets appended to (e.g., /var/log/messages),
     pattern: a string (can use bash's extended pathname globbing syntax),
     command: the command to run when the previous pattern is seen.


DESCRIPTION

    Onlogdo is a hack to handle a common problem: when a certain
    message shows up in a log file, an action should be performed.
    E.g.: when a PC-card network device is inserted, it should be
    ifconfig'd or perhaps dhclient should be run. This program can do
    that in a fairly reasonable way.

    Onlogdo continuously reads lines as they are appended to a log
    file. When a line matches a given pattern, the command associated
    with that pattern is run in the background. The patterns
    recognized are standard pathname globbing (*, ?, []) plus bash's
    extended pattern matching (extglob) syntax (see bash(1)).

    The log file is reopened properly, if the log file being read is
    rotated. Also, since it blocks when waiting for new lines, onlogdo
    takes up almost no CPU time.


PATTERN MATCHING SYNTAX

    Don't worry about learning the pattern matching the first time you
    read this manual; you'll rarely need it, unless you're anal about
    being as succinct as possible. (Like the author).

    The following is an excerpt from bash's man page; see bash(1) for
    full details. In the following description, a pattern-list is a
    list of one or more patterns separated by a |. Composite patterns
    may be formed using one or more of the following sub-patterns:

       *      Matches any string, including the null string.

       ?      Matches any single character.

       [...]  Matches any one of the enclosed characters. A pair of
              characters separated by a hyphen denotes a range
              expression. If the first character following the [ is a
              ! or a ^ then any character not enclosed is matched.

      ?(pattern-list)
	     Matches zero or one occurrence of the  given patterns
      *(pattern-list)
	     Matches  zero  or  more  occurrences  of the given patterns
      +(pattern-list)
	     Matches one or more occurrences of the given patterns
      @(pattern-list)
	     Matches exactly one of the given patterns
      !(pattern-list)
	     Matches  anything  except  one  of the given patterns


EXAMPLES

    Pipelines are okay:
      onlogdo /var/log/messages '*' 'sleep 5; echo olleH | rev'

    Wildcards match filenames as usual in a command:
      onlogdo /var/log/messages 'Segfault' 'rm /*.core'

    Multiple pattern and command pairs are allowed:
      onlogdo /var/log/messages \
	    'ep0 at pcmcia' '/etc/rc.d/dhclient start' \
	    'ep0 detached'  '/etc/rc.d/dhclient stop'  \
	    'wi0 at pcmcia' '/etc/rc.d/dhclient start' \
	    'wi0 detached'  '/etc/rc.d/dhclient stop'

    Bash's extended pathname globbing to do the same as above:
      onlogdo /var/log/messages \
	    '@(ep|wi)[0-9] at pcmcia' '/etc/rc.d/dhclient start' \
	    '@(ep|wi)[0-9] detached'  '/etc/rc.d/dhclient stop'

    A useful example for NetBSD/hpcmips:
      onlogdo /var/log/messages 'hpcapm: resume' 'sleep 1; xrefresh'

    Under NetBSD/hpcmips-1.5.1, the X server screen is overwritten by the
    console on an APM resume. I put the last &quot;onlogdo&quot; example in my
    system xinitrc, so xrefresh will be run automatically. (The sleep
    is there to wait for the console to finish junking up the screen).


SEE ALSO

    tail(1), bash(1)

BUGS

    If this had been written in Perl it would have used &quot;normal&quot;
    regexp syntax instead of pathname expansion. Bash's extensions
    make the patterns as powerful as regexps, but more recondite.

    There is no (documented) way for a command to refer to specifics
    in the line that matched. E.g., if the pattern was &quot;@(ep|wi)0&quot;,
    the command wouldn't know if the line contained ep0 or wi0.

    The author has spent way too much time perfecting a kludge. No
    matter what you're using onlogdo for, there's probably a more
    &quot;correct&quot; way to do it. On the other hand, onlogdo is widely
    applicable and easy to use, so at least you won't be wasting much
    time while doing it the &quot;wrong&quot; way.

    There should be a real man page.


AUTHOR

    Ben Wong &lt;Benjamin.Wong@cc.gatech.edu&gt;


HISTORY

    Onlogdo started life as a one line kludge to work around a bug in
    the interaction between APM and the X server in NetBSD-1.5/hpcmips
    in September of 2001.

EOF
}





### USAGE AND ARGUMENT SANITY CHECKING ###

if [[ $# -lt 3 ]]; then
    showmanpage
    exit 1
fi

# Emacs's syntax highlighting doesn't handle single ticks (') properly.



# Check if -v (verbose) flag was given.
if [[ &quot;$1&quot; == &quot;-v&quot; ]]; then 
    ifverbose=echo		# Echo commands verbosely, if -v.
    shift
else
    ifverbose=:			# Usually just run a no-op.
fi


# Make sure the log file is readable.
if [[ ! -r &quot;$1&quot; ]]; then
    echo &quot;onlogdo: \&quot;$1\&quot; is not readable&quot; &gt;&amp;2
    exit 1
fi
if [[ -d &quot;$1&quot; ]]; then
    echo &quot;onlogdo: \&quot;$1\&quot; is a directory&quot; &gt;&amp;2
    exit 1
fi






### SIGNAL HANDLING AND EXIT CLEANUP ###

# Run cleanup function when shell exits.
trap cleanup EXIT


cleanup () {
    echo &quot;onlogdo: cleaning up...&quot; &gt;&amp;2
    if [[ &quot;$TAILPID&quot; ]]; then
	kill $TAILPID		# Kill the bg tail process.
    fi
    rm -f &quot;$PIPE&quot;		# Delete the named pipe.
    rmdir &quot;$PIPEDIR&quot;
    return 0
}




### MAIN ROUTINE STARTS HERE ###

# Don't expand wildcards in pattern arguments as filenames.
set -o noglob

# Use bash's extended pattern matching operators
shopt -s extglob

# Create a pipe to read the log file a line at a time; 
# Use mktemp for security.

PIPEDIR=$(mktemp -d /tmp/onlogdo.XXXXXX)
PIPE=&quot;$PIPEDIR/$(echo $1 | sed 's#^/##; s#/#.#g')&quot;	# var.log.messages
rm -f $PIPE
mknod $PIPE p
tail -Fn0 $1 &gt;$PIPE &amp;		# FSF tail: &quot;tail --retry -fn0&quot;
TAILPID=$!
exec 5&lt; $PIPE

# Copy the positional paramaters in to a variable that can be indexed.
params=(&quot;$0&quot; &quot;$@&quot;)


# Repeatedly read from the pipe, process each line.
while :; do
    while read REPLY &lt;&amp;5; do

	$ifverbose -e &quot;\nline: \&quot;$REPLY\&quot;&quot;
	for ((i=2; i&lt;$#; i+=2)); do
	    pattern=${params[$i]}
	    command=${params[$((i+1))]}
	    $ifverbose &quot;pattern: \&quot;$pattern\&quot;&quot;
	    if [[ -z &quot;${REPLY##*$pattern*}&quot; ]]; then
		$ifverbose &quot;*MATCHED*&quot;
		$ifverbose &quot;command: \&quot;$command\&quot;&quot;
		set +o noglob	# Allow pathname matching in commands
		eval $command &amp;
		set -o noglob	# No pathname expansion for patterns
	    fi
	done
    done

    # We get here whenever the pipe first blocks (returns EOF)
    sleep 1			# Don't loop too quickly
done


### MAIN ROUTINE ENDS HERE ###


# Note: if we ever get here, the cleanup() function will be called
# automatically since we're trapping on signal 0.</pre> <a href="http://www.posteet.com/tags/bash">[bash]</a>  <a href="http://www.posteet.com/tags/cron">[cron]</a>  <a href="http://www.posteet.com/tags/log">[log]</a>  <a href="http://www.posteet.com/tags/shell">[shell]</a>  <a href="http://www.posteet.com/tags/tail">[tail]</a> ]]>        </description>
        <dc:creator>spirit</dc:creator>
        <pubDate>Thu, 09 Oct 2008 12:09:30 +0000</pubDate>

            <category>bash</category>
            <category>cron</category>
            <category>log</category>
            <category>shell</category>
            <category>tail</category>
    
    </item>

  
    <item>
        <title>Commande pour faire un fichier tar gzippé</title>
        <link>http://www.posteet.com/view/1299</link>
        <description>
        <![CDATA[<pre>Exemple pour créer un fichier compressé à partir d’un répertoire de log (il s’agit du dernier paramètre, ici le nom du répertoire est la date au format YYYY-MM-DD) :

tar czf archives-log-2008-10-02.tgz 2008-10-02</pre> <a href="http://www.posteet.com/tags/compression">[compression]</a>  <a href="http://www.posteet.com/tags/fichier">[fichier]</a>  <a href="http://www.posteet.com/tags/log">[log]</a>  <a href="http://www.posteet.com/tags/répertoire">[répertoire]</a> ]]>        </description>
        <dc:creator>cyo</dc:creator>
        <pubDate>Fri, 03 Oct 2008 14:20:43 +0000</pubDate>

            <category>compression</category>
            <category>fichier</category>
            <category>log</category>
            <category>répertoire</category>
    
    </item>

  
    <item>
        <title>Trouver les logs de connections sur un serveur Apache</title>
        <link>http://www.posteet.com/view/1279</link>
        <description>
        <![CDATA[<pre>Regarder dans le répertoire :
/var/log/httpd</pre> <a href="http://www.posteet.com/tags/apache">[apache]</a>  <a href="http://www.posteet.com/tags/log">[log]</a> ]]>        </description>
        <dc:creator>cyo</dc:creator>
        <pubDate>Tue, 23 Sep 2008 09:51:32 +0000</pubDate>

            <category>apache</category>
            <category>log</category>
    
    </item>

  
    <item>
        <title>Récupèrer les dernières lignes d'un fichier texte</title>
        <link>http://www.posteet.com/view/1277</link>
        <description>
        <![CDATA[<pre>On peut afficher les dernières lignes d’un fichier ou afficher en continu les ajouts à un fichier, ce qui peut être très utile pour surveiller un fichier de log (anglais: logfile), respectivement:

tail nom_fichier
tail -f nom_fichier

Dans ce dernier cas, on interrompt la commande avec CTRL-C.</pre> <a href="http://www.posteet.com/tags/affichage">[affichage]</a>  <a href="http://www.posteet.com/tags/bash">[bash]</a>  <a href="http://www.posteet.com/tags/fichier">[fichier]</a>  <a href="http://www.posteet.com/tags/log">[log]</a>  <a href="http://www.posteet.com/tags/texte">[texte]</a> ]]>        </description>
        <dc:creator>cyo</dc:creator>
        <pubDate>Tue, 23 Sep 2008 09:06:19 +0000</pubDate>

            <category>affichage</category>
            <category>bash</category>
            <category>fichier</category>
            <category>log</category>
            <category>texte</category>
    
    </item>

  
    <item>
        <title>Créer un fichier compressé tar.gz sur un serveur Unix</title>
        <link>http://www.posteet.com/view/839</link>
        <description>
        <![CDATA[<pre>Crée un fichier 'sql.tar.gz' à partir de logs d’erreur 'sql-2008-03*' :
tar cvfz sql.tar.gz sql-2008-03*

puis déplace le fichier dans le répertoire supérieur :
mv sql.tar.gz ../</pre> <a href="http://www.posteet.com/tags/bash">[bash]</a>  <a href="http://www.posteet.com/tags/compression">[compression]</a>  <a href="http://www.posteet.com/tags/fichier">[fichier]</a>  <a href="http://www.posteet.com/tags/log">[log]</a>  <a href="http://www.posteet.com/tags/serveur">[serveur]</a>  <a href="http://www.posteet.com/tags/shell">[shell]</a>  <a href="http://www.posteet.com/tags/winscp">[winscp]</a> ]]>        </description>
        <dc:creator>cyo</dc:creator>
        <pubDate>Tue, 18 Mar 2008 09:30:22 +0000</pubDate>

            <category>bash</category>
            <category>compression</category>
            <category>fichier</category>
            <category>log</category>
            <category>serveur</category>
            <category>shell</category>
            <category>winscp</category>
    
    </item>

  
    <item>
        <title>Rotation des logs Apache</title>
        <link>http://www.posteet.com/view/440</link>
        <description>
        <![CDATA[<pre>Faire tourner les logs avec une taille de 1 Mo sous Windows :
ErrorLog &quot;|bin/rotatelogs.exe logs/htdocs-error_log 1M&quot;

Exemple complet :
&lt;VirtualHost *:8080&gt;
    DocumentRoot c:\htdocs
    ErrorLog &quot;|bin/rotatelogs.exe logs/htdocs-error_log 1M&quot;
    CustomLog logs/htdocs-access_log common
&lt;/VirtualHost&gt;</pre> <a href="http://www.posteet.com/tags/apache">[apache]</a>  <a href="http://www.posteet.com/tags/log">[log]</a>  <a href="http://www.posteet.com/tags/rotation">[rotation]</a> ]]>        </description>
        <dc:creator>skymaxs</dc:creator>
        <pubDate>Thu, 15 Nov 2007 10:06:05 +0000</pubDate>

            <category>apache</category>
            <category>log</category>
            <category>rotation</category>
    
    </item>


</channel>
</rss>
