Table of Contents

概要

  • バックアップ終了時に、既定アカウントにレポートをメールする。
  • nohup と組み合わせて使う想定。
    # nohup ~/BackupWithReport.sh dest/ file1 file2 file3 &

ソース

  • BackupWithReport.zip
    #!/bin/bash
    # 目的ディレクトリに、指定されたファイル群をコピーする。
    # 処理終了時に、開始時刻, 終了時刻, 処理ファイル名を既定のアドレスへメールする。
    
    account=root
    scriptname="${0##*/}"
    
    if [ $# -lt 2 ]; then
      cat << EOL
    説明: 目的ディレクトリに、指定されたファイル群をコピーする。
          処理終了時にレポートを既定のアカウント(${account})へメールする。
    使用法: ${scriptname} <dest> <file1> <file2> ...
    EOL
      exit 1
    fi
    
    report=`mktemp`
    dest="$1"
    shift
    
    echo "Destination:" >> ${report}
    echo "${dest}" >> ${report}
    echo >> ${report}
    echo "Start:" >> ${report}
    date >> ${report}
    echo >> ${report}
    echo "Files:" >> ${report}
    
    for arg in "$@"
    do
      echo "${arg}" >> ${report}
      cp -ruv "${arg}" "${dest}"
    done
    echo >> ${report}
    
    echo "Finish:" >> ${report}
    date >> ${report}
    
    cat ${report} | mail -s "${scriptname} report" ${account}
    rm -f ${report}