検索せずに古いフォルダを消去する

検索せずに古いフォルダを消去する

ここでは、xdaysより古い古いフォルダを削除しようとしています。これらのディスクへのパスはfile_path.txtに記載されています。

ここで必要なのは、上記のファイルから利用可能なすべてのパスを検索し、利用可能なパスを削除することです。

これまで成功していないまま試した内容は次のとおりです。

dir_to_check='file_path.txt'
CY=`date +"%Y"`
last_month=`date '+%B' --date '1 month ago'`
lmdate=`date '+%d' --date='32 days ago'`

cmd="$dir_to_check/$CY/$last_month/$lmdate"

cat file_path.txt | while read output
do
find $cmd -type d -ctime +30
if [ $? -eq 0 ]; then
echo "Directory exists and can be deleted"
echo "rm dir"
else
echo "FAIL to delete directory as its not exists"
fi
done

ベストアンサー1

アルゴリズムで発生する可能性のあるエラー:

dir_to_check='file_path.txt'
CY=`date +"%Y"`
last_month=`date '+%B' --date '1 month ago'`
lmdate=`date '+%d' --date='32 days ago'`

cmd="/$CY/$last_month/$lmdate"

cat $dir_to_check | while read output
do
        find ${output}${cmd} -type d -ctime +30 
        if [ $? -eq 0 ]; then
                echo "Directory exists and can be deleted"
                echo "rm dir"
        else
                echo "FAIL to delete directory as its not exists"
        fi  
done

戻り値の代わりにユーティリティ-execのオプションを使用することを検討してください。find$?

おすすめ記事