Created
August 14, 2013 13:21
-
-
Save gceylan/6230954 to your computer and use it in GitHub Desktop.
son günün anısına
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/bash | |
DIR_PATH=`pwd` # varsayılan olarak çalıştırıldığı dizinden başla | |
FILE_FORMAT=".txt" # varsayılan olarak txt uzantıları seç | |
N_DAYS=30 # 30 gün öncesinden başla | |
while getopts ":p:d:f:" opt; do | |
case $opt in | |
p) | |
DIR_PATH=$OPTARG | |
;; | |
d) | |
N_DAYS=$OPTARG | |
;; | |
f) | |
FILE_FORMAT=$OPTARG | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
echo "logların silineceği dizin: $DIR_PATH" | |
echo "silinecek log dosya formatı: $FILE_FORMAT" | |
echo "$N_DAYS gün öncesinden başlanacak..." | |
function run_process() | |
{ | |
local mon=$[ $N_DAYS*24*60*60 ] | |
for file in $( find $DIR_PATH -type f -name "*$FILE_FORMAT" ); do | |
if [ -f $file ]; then | |
local mod_secs=$(date --utc --reference=$file +%s) | |
local now_secs=$(date +%s) | |
local delta=$[ $now_secs-$mod_secs ] | |
local day=$[ $delta/(24*60*60) ] | |
if [ $delta -lt $mon ]; then | |
echo $file " -> modification $day day ago..." | |
else | |
#rm $file | |
echo "INFO [deleted...] file: $file - last modifided day: $day" | |
fi | |
fi | |
done | |
return 1 | |
} | |
read -p "$DIR_PATH dizinindeki $FILE_FORMAT formatındaki tüm loglar silinecek? (e/h): " CONT | |
if [ "$CONT" == "e" ]; then | |
run_process | |
else | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment