make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / fixlogfiledatetime
blob92ef3d1b3c2a59439a5ac75ea10f4f34185d3ff2
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 fixlogfiledatetime - Set the target files modification time to their respective last log entry's timestamp
10 =cut
12 EOF
15 set -e
17 anytail()
19 case ${1##*.} in
20 gz) zcat "$1" | tail -n1;;
21 bz|bz2) bzcat "$1" | tail -n1;;
22 xz) xzcat "$1" | tail -n1;;
23 Z) compress -d -c "$1" | tail -n1;;
24 *) tail -n1 "$1";;
25 esac
28 help_text="Please give a perl(1) expression in DATETIME_PATTERN env variable to match and extract the datetime from log files. Example: 's/^[^>]+>((\S+\s+){3}).*/\$1/'"
30 for f in "$@"
32 dtstr=$(anytail "$f" | perl -ne "${DATETIME_PATTERN?$help_text} and print")
33 echo "$f $dtstr"
34 touch "$f" -t $(date +%Y%m%d%H%M.%S -d "$dtstr")
35 done