백업 또는 아키이브한 디렉토리를 몇개만 남기고 오래된 것 부터 지워 버리기..
[XXXX] cat cleanup_archive.sh
#!/bin/sh
# This script is for cleanning up the archives
# $1 archive count
_file_lines=""
_archive="/usr02/bfuser/bin"
_count=0
_total=30
if [ $# -eq 1 ]; then
_total=$1
else
echo "Using default ${_total}"
fi
echo "Start deleting archive more than ${_total}"
_file_lines=`ls -alt ${_archive} | grep "RL" | awk '{print $9}'`
echo "${_file_lines}"
echo "Start Deleting.."
for file_name in ${_file_lines}
do
_count=`expr ${_count} + 1`
if [ ${_count} -gt ${_total} ]; then
echo "Deleting.... ${_count} ${_archive}/${file_name}"
rm -rf ${_archive}/${file_name}
else
echo "Skipping.... ${_count} ${_archive}/${file_name}"
fi
done
이 글은 스프링노트에서 작성되었습니다.