Last-modified: 2014-08-18 (月) 03:32:09
スクリプト/gomi-checker_d.sh

概要

アップデートなどによって作られる不要ファイルを削除するスクリプトです。

コード

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
-
!
-
|
|
!
-
!
-
!
-
!
-
!
 
 
 
 
 
 
-
!
 
 
 
 
 
 
-
!
 
 
-
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
-
!
-
!
 
-
-
-
-
-
|
|
!
!
|
|
-
-
-
-
-
|
|
!
!
|
|
-
-
|
!
|
-
!
|
#!/bin/bash
 
#
# アップデートなどによって作られる不要ファイルを削除するスクリプト
#
 
#///////////////////////////////////////////////////////////
 
# 送信先アドレス
MAIL_ADDRESS="[email protected]"
# 件名
MAIL_TITLE="[$(hostname)] 不要ファイル削除報告"
# チェックするパス1
CHECK_PATH1=(
    /etc/cron.d/
    /etc/cron.daily/
    /etc/cron.hourly/
    /etc/cron.monthly/
    /etc/cron.weekly/
)
# チェックするファイルリスト1
DENNY_LIST1=(
    chkrootkit
    rkhunter
    tripwire
    avira_updater
    logrotate
)
# チェックするパス2
CHECK_PATH2=(
    /etc/logrotate.d/
)
# チェックするファイルリスト2
DENNY_LIST2=(
    apt
    aptitude
    avira
    cron-apt
    dpkg
    exim4-base
    exim4-paniclog
    munin
    munin-node
    nginx
    rkhunter
    ntpdate
)
 
# メールパス
MAIL=/usr/bin/mail
 
#///////////////////////////////////////////////////////////
 
# テンポラリファイル名作成
OUTFILE=`/bin/mktemp` || exit 1
 
for path in ${CHECK_PATH1[*]}
do
    for file in ${DENNY_LIST1[*]}
    do
        if test -f $path$file; then
            /bin/rm $path$file
            echo $path$file >> $OUTFILE
        fi
    done
done
 
for path in ${CHECK_PATH2[*]}
do
    for file in ${DENNY_LIST2[*]}
    do
        if test -f $path$file; then
            /bin/rm $path$file
            echo $path$file >> $OUTFILE
        fi
    done
done
 
# $OUTFILEに出力があれば、メールする
if [ -s "$OUTFILE" ]; then
    /bin/cat $OUTFILE | tr -d '\r' | $MAIL -s "$MAIL_TITLE" "$MAIL_ADDRESS"
fi
 
# テンポラリファイル削除
/bin/rm -f $OUTFILE

検証時の環境