Tags: log

Sort by: Date / Title /

  1. 7 years ago by spirit
    1. # Add the file /etc/logrotate.d/nginx with the following content:
    2. /path/to/log/nginx_* {
    3.     missingok
    4.     notifempty
    5.     compress
    6.     sharedscripts
    7.     postrotate
    8.         test ! -f /var/run/nginx.pid || kill -USR1 `cat /var/run/nginx.pid`
    9.     endscript 
    10. }
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1999"></script>
  2. 8 years ago by cyo
    1. Exemple avec des fichiers nommés "cp-2008-...." :
    2. for files in cp-2008-* ; do rm -f $file ; done
    3.  
    4. Autre solution :
    5. find . -name "*.toto" -exec rm {} \;
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1654"></script>
  3. 8 years ago by cyo
    1. wget --timeout=0 -q -t 1 -O -  http://127.0.0.1/path/file.php >result.txt 2>result.txt
    2. SORTIE=`cat result.txt | tr '\015\012' ' '`
    3. echo $SORTIE
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1395"></script>
  4. sponsorised links
  5. 8 years ago by cyo
    1. wget http://exemple.com/index.php >result.txt 2>result.txt
    2. FICHIER=`sed '/^$/d' result.txt | head -1 | cut -d" " -f2-20`
    3. RETOUR=`sed '/^$/d' result.txt | tail -1`
    4. DATEHEURE=`date "+%Y-%m-%d %H:%m:%S"`
    5. touch flux.log
    6. echo "$DATEHEURE -$FICHIER : $RETOUR" >>flux.log
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1371"></script>
  6. 9 years ago by spirit
    Lire continuellement un fichier de log et en cas de détection d'une chaine, exécuter une liste de commande
    1. #!/bin/sh
    2. tail -fn0 /var/log/file.log | while read line ; do
    3.         echo "$line" | grep "pattern"
    4.         if [ $? = 0 ]
    5.         then
    6.                 # Actions
    7.                 echo "Yeah: $line"
    8.         fi
    9. done
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1311"></script>
  7. 9 years ago by spirit
    # onlogdo: a hack to handle a common problem: when a certain message shows up in the log file, an action should be performed. (credits to Ben Wong)
    1. #!/bin/bash
    2.  
    3. # Author: Ben Wong <ben@wongs.net>
    4. # Created on: <2001-08-08 11:56:03 hackerb9>
    5. # Time-stamp: <2002-11-20 14:13:11 bbb>
    6.  
    7. # onlogdo: a hack to handle a common problem: when a certain message
    8. # shows up in the log file, an action should be performed. E.g.: when
    9. # a PC-card network device is inserted, it should be ifconfig'd or
    10. # perhaps dhclient should be run. This program can do that in a fairly
    11. # reasonable way.
    12.  
    13.  
    14.  
    15. ### FIRST, THE HELPER FUNCTIONS ###
    16.  
    17. function showmanpage () {
    18.     cat <<'EOF'
    19. NAME
    20.  
    21.    onlogdo - monitor a log file and execute commands based on patterns
    22.  
    23.  
    24. SYNOPSIS
    25.  
    26.    onlogdo <logfile> <pattern> <command> [ <pattern> <command> ... ]
    27.  
    28.      logfile: a file that gets appended to (e.g., /var/log/messages),
    29.      pattern: a string (can use bash's extended pathname globbing syntax),
    30.      command: the command to run when the previous pattern is seen.
    31.  
    32.  
    33. DESCRIPTION
    34.  
    35.     Onlogdo is a hack to handle a common problem: when a certain
    36.     message shows up in a log file, an action should be performed.
    37.     E.g.: when a PC-card network device is inserted, it should be
    38.     ifconfig'd or perhaps dhclient should be run. This program can do
    39.     that in a fairly reasonable way.
    40.  
    41.     Onlogdo continuously reads lines as they are appended to a log
    42.     file. When a line matches a given pattern, the command associated
    43.     with that pattern is run in the background. The patterns
    44.     recognized are standard pathname globbing (*, ?, []) plus bash's
    45.     extended pattern matching (extglob) syntax (see bash(1)).
    46.  
    47.     The log file is reopened properly, if the log file being read is
    48.     rotated. Also, since it blocks when waiting for new lines, onlogdo
    49.     takes up almost no CPU time.
    50.  
    51.  
    52. PATTERN MATCHING SYNTAX
    53.  
    54.     Don't worry about learning the pattern matching the first time you
    55.     read this manual; you'll rarely need it, unless you're anal about
    56.     being as succinct as possible. (Like the author).
    57.  
    58.     The following is an excerpt from bash's man page; see bash(1) for
    59.     full details. In the following description, a pattern-list is a
    60.     list of one or more patterns separated by a |. Composite patterns
    61.     may be formed using one or more of the following sub-patterns:
    62.  
    63.        *      Matches any string, including the null string.
    64.  
    65.        ?      Matches any single character.
    66.  
    67.        [...]  Matches any one of the enclosed characters. A pair of
    68.               characters separated by a hyphen denotes a range
    69.               expression. If the first character following the [ is a
    70.               ! or a ^ then any character not enclosed is matched.
    71.  
    72.       ?(pattern-list)
    73.              Matches zero or one occurrence of the  given patterns
    74.       *(pattern-list)
    75.              Matches  zero  or  more  occurrences  of the given patterns
    76.       +(pattern-list)
    77.              Matches one or more occurrences of the given patterns
    78.       @(pattern-list)
    79.              Matches exactly one of the given patterns
    80.       !(pattern-list)
    81.              Matches  anything  except  one  of the given patterns
    82.  
    83.  
    84. EXAMPLES
    85.  
    86.     Pipelines are okay:
    87.       onlogdo /var/log/messages '*' 'sleep 5; echo olleH | rev'
    88.  
    89.     Wildcards match filenames as usual in a command:
    90.       onlogdo /var/log/messages 'Segfault' 'rm /*.core'
    91.  
    92.     Multiple pattern and command pairs are allowed:
    93.       onlogdo /var/log/messages \
    94.             'ep0 at pcmcia' '/etc/rc.d/dhclient start' \
    95.             'ep0 detached'  '/etc/rc.d/dhclient stop\
    96.             'wi0 at pcmcia' '/etc/rc.d/dhclient start' \
    97.             'wi0 detached'  '/etc/rc.d/dhclient stop'
    98.  
    99.     Bash's extended pathname globbing to do the same as above:
    100.       onlogdo /var/log/messages \
    101.             '@(ep|wi)[0-9] at pcmcia' '/etc/rc.d/dhclient start' \
    102.             '@(ep|wi)[0-9] detached'  '/etc/rc.d/dhclient stop'
    103.  
    104.     A useful example for NetBSD/hpcmips:
    105.       onlogdo /var/log/messages 'hpcapm: resume' 'sleep 1; xrefresh'
    106.  
    107.     Under NetBSD/hpcmips-1.5.1, the X server screen is overwritten by the
    108.     console on an APM resume. I put the last "onlogdo" example in my
    109.     system xinitrc, so xrefresh will be run automatically. (The sleep
    110.     is there to wait for the console to finish junking up the screen).
    111.  
    112.  
    113. SEE ALSO
    114.  
    115.     tail(1), bash(1)
    116.  
    117. BUGS
    118.  
    119.     If this had been written in Perl it would have used "normal"
    120.     regexp syntax instead of pathname expansion. Bash's extensions
    121.     make the patterns as powerful as regexps, but more recondite.
    122.  
    123.     There is no (documented) way for a command to refer to specifics
    124.     in the line that matched. E.g., if the pattern was "@(ep|wi)0",
    125.     the command wouldn't know if the line contained ep0 or wi0.
    126.  
    127.     The author has spent way too much time perfecting a kludge. No
    128.     matter what you're using onlogdo for, there's probably a more
    129.     "correct" way to do it. On the other hand, onlogdo is widely
    130.     applicable and easy to use, so at least you won't be wasting much
    131.     time while doing it the "wrong" way.
    132.  
    133.     There should be a real man page.
    134.  
    135.  
    136. AUTHOR
    137.  
    138.     Ben Wong <Benjamin.Wong@cc.gatech.edu>
    139.  
    140.  
    141. HISTORY
    142.  
    143.     Onlogdo started life as a one line kludge to work around a bug in
    144.     the interaction between APM and the X server in NetBSD-1.5/hpcmips
    145.     in September of 2001.
    146.  
    147. EOF
    148. }
    149.  
    150.  
    151.  
    152.  
    153.  
    154. ### USAGE AND ARGUMENT SANITY CHECKING ###
    155.  
    156. if [[ $# -lt 3 ]]; then
    157.     showmanpage
    158.     exit 1
    159. fi
    160.  
    161. # Emacs's syntax highlighting doesn't handle single ticks (') properly.
    162.  
    163.  
    164.  
    165. # Check if -v (verbose) flag was given.
    166. if [[ "$1" == "-v" ]]; then
    167.     ifverbose=echo            # Echo commands verbosely, if -v.
    168.     shift
    169. else
    170.     ifverbose=:   # Usually just run a no-op.
    171. fi
    172.  
    173.  
    174. # Make sure the log file is readable.
    175. if [[ ! -r "$1" ]]; then
    176.     echo "onlogdo: \"$1\" is not readable" >&2
    177.     exit 1
    178. fi
    179. if [[ -d "$1" ]]; then
    180.     echo "onlogdo: \"$1\" is a directory" >&2
    181.     exit 1
    182. fi
    183.  
    184.  
    185.  
    186.  
    187.  
    188.  
    189. ### SIGNAL HANDLING AND EXIT CLEANUP ###
    190.  
    191. # Run cleanup function when shell exits.
    192. trap cleanup EXIT
    193.  
    194.  
    195. cleanup () {
    196.     echo "onlogdo: cleaning up..." >&2
    197.     if [[ "$TAILPID" ]]; then
    198.         kill $TAILPID      # Kill the bg tail process.
    199.     fi
    200.     rm -f "$PIPE"              # Delete the named pipe.
    201.     rmdir "$PIPEDIR"
    202.     return 0
    203. }
    204.  
    205.  
    206.  
    207.  
    208. ### MAIN ROUTINE STARTS HERE ###
    209.  
    210. # Don't expand wildcards in pattern arguments as filenames.
    211. set -o noglob
    212.  
    213. # Use bash's extended pattern matching operators
    214. shopt -s extglob
    215.  
    216. # Create a pipe to read the log file a line at a time;
    217. # Use mktemp for security.
    218.  
    219. PIPEDIR=$(mktemp -d /tmp/onlogdo.XXXXXX)
    220. PIPE="$PIPEDIR/$(echo $1 | sed 's#^/##; s#/#.#g')"      # var.log.messages
    221. rm -f $PIPE
    222. mknod $PIPE p
    223. tail -Fn0 $1 >$PIPE &      # FSF tail: "tail --retry -fn0"
    224. TAILPID=$!
    225. exec 5< $PIPE
    226.  
    227. # Copy the positional paramaters in to a variable that can be indexed.
    228. params=("$0" "$@")
    229.  
    230.  
    231. # Repeatedly read from the pipe, process each line.
    232. while :; do
    233.     while read REPLY <&5; do
    234.  
    235.         $ifverbose -e "\nline: \"$REPLY\""
    236.         for ((i=2; i<$#; i+=2)); do
    237.             pattern=${params[$i]}
    238.             command=${params[$((i+1))]}
    239.             $ifverbose "pattern: \"$pattern\""
    240.             if [[ -z "${REPLY##*$pattern*}" ]]; then
    241.                 $ifverbose "*MATCHED*"
    242.                 $ifverbose "command: \"$command\""
    243.                 set +o noglob   # Allow pathname matching in commands
    244.                 eval $command &
    245.                 set -o noglob   # No pathname expansion for patterns
    246.             fi
    247.         done
    248.     done
    249.  
    250.     # We get here whenever the pipe first blocks (returns EOF)
    251.     sleep 1               # Don't loop too quickly
    252. done
    253.  
    254.  
    255. ### MAIN ROUTINE ENDS HERE ###
    256.  
    257.  
    258. # Note: if we ever get here, the cleanup() function will be called
    259. # automatically since we're trapping on signal 0.
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1309"></script>
  8. 9 years ago by cyo
    1. 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) :
    2.  
    3. tar czf archives-log-2008-10-02.tgz 2008-10-02
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1299"></script>
  9. 9 years ago by cyo
    Regarder dans le répertoire :
    /var/log/httpd
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1279"></script>
  10. 9 years ago by cyo
    1. 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:
    2.  
    3. tail nom_fichier
    4. tail -f nom_fichier
    5.  
    6. Dans ce dernier cas, on interrompt la commande avec CTRL-C.
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/1277"></script>
  11. 9 years ago by cyo
    1. Crée un fichier 'sql.tar.gz' à partir de logs d’erreur 'sql-2008-03*' :
    2. tar cvfz sql.tar.gz sql-2008-03*
    3.  
    4. puis déplace le fichier dans le répertoire supérieur :
    5. mv sql.tar.gz ../
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/839"></script>

First / Previous / Next / Last / Page 1 of 2 (11 posteets)