-
-
Save masakuni-ito/c8cd67b77b650d09df1ef0b9c02baed3 to your computer and use it in GitHub Desktop.
指定したディレクトリのファイルをアーカイブする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
FROM="your_nice_mail@example.com" | |
TO="your_nice_mail@example.com" | |
TARGET_DIRS=("/Users/example/.Trash" "/Users/example/Desktop/work/tmp" "/Users/example/Downloads") | |
ARCHIVE_DIR=/Users/example/Desktop/misc/archives | |
TMP_DIR=/tmp/`date "+%Y%m%d%H%M%S"`_junk | |
BODY="" | |
# コピー | |
mkdir ${TMP_DIR} | |
for TARGET_DIR in ${TARGET_DIRS[@]}; do | |
cp -r ${TARGET_DIR} ${TMP_DIR} | |
done | |
# 圧縮 | |
cd $(dirname ${TMP_DIR}) | |
BODY=$(tar cvfz ${TMP_DIR}.tar.gz $(basename ${TMP_DIR}) 2>&1) | |
mv ${TMP_DIR}.tar.gz ${ARCHIVE_DIR} | |
# 削除 | |
rm -rf ${TMP_DIR} | |
for TARGET_DIR in ${TARGET_DIRS[@]}; do | |
rm -rf ${TARGET_DIR}/* | |
done | |
# メール | |
{ | |
echo "From: "${FROM} | |
echo "To: "${TO} | |
echo "Subject: "`date "+%Y/%m/%d %H:%M:%S"`" junk files" | |
echo | |
echo "$BODY" | sort | |
} | sendmail -i -f ${FROM} ${TO} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment