/admin/docker

To get this branch, use:
bzr branch http://darksoft.org/webbzr/admin/docker

« back to all changes in this revision

Viewing changes to adei/adei/scripts/log.sh

  • Committer: Suren A. Chilingaryan
  • Date: 2016-12-23 19:40:10 UTC
  • Revision ID: csa@suren.me-20161223194010-1013mnipk5revl6m
Initial release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/bash
 
2
 
 
3
max_age=10
 
4
max_mails=10
 
5
log_lines=50
 
6
 
 
7
cur=`date +%s`
 
8
since=$(($cur - $max_age * 60))
 
9
 
 
10
echo "Apache error log"
 
11
echo "================"
 
12
tail -n $log_lines /var/log/apache2/error_log | perl -MDateTime::Format::Strptime -F';' -ane '
 
13
    my $parser = DateTime::Format::Strptime->new(
 
14
        pattern => "%a %b %d %H:%M:%S.%N %Y"
 
15
    );
 
16
    my $formater = DateTime::Format::Strptime->new(
 
17
        pattern => "%s"
 
18
    );
 
19
    if (/^\[([^]]+)\]/) {
 
20
        $last = $formater->format_datetime($parser->parse_datetime($1));
 
21
    } elsif ($last !~ /\d+/) {
 
22
        $last = 0;
 
23
    }
 
24
    print "$last $_\n";
 
25
' | awk "{ if (\$1 > $since) print \$0 }" | cut -d ' ' -f 2-
 
26
echo
 
27
echo
 
28
 
 
29
 
 
30
mails=`mailutil check | cut -d ' ' -f 6`
 
31
if [ "$mails" == "in" ]; then
 
32
    mails=`mailutil check | cut -d ' ' -f 4`
 
33
fi
 
34
 
 
35
if [ $mails -gt 0 ]; then
 
36
    [ $mails -gt $max_mails ] && mails=$max_mails
 
37
 
 
38
    cur=`date -u +%s`
 
39
    for id in `seq $mails -1 1`; do
 
40
        mail=$(($mails - $id + 1))
 
41
        
 
42
        lastmail=`echo "type $mail" | mailx -R "" -N`
 
43
        dt=`echo "$lastmail" | grep "From" | head -n 1 | cut -d ' ' -f 3-`
 
44
        last=`date -u --date "$dt" +%s`
 
45
        since=$((($cur - $last) / 60))
 
46
        if [ $since -le $max_age ]; then
 
47
            echo "Cron reports on$dt"
 
48
            echo "========================================"
 
49
            echo "$lastmail" | sed -e '1,/^$/d' | head -n 10
 
50
            echo
 
51
            echo
 
52
        fi
 
53
    done
 
54
fi