Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- FILEPREFIX="dailyfilename_"
- AGE=7
- [ -z "$1" ] && echo "Usage: $0 DIR\ne.g. : $0 ." && exit
- DIR="$1"
- cd $DIR || { echo "Can't change directory to $DIR"; exit; }
- LIST=${FILEPREFIX}*
- [ -z "$LIST" ] && echo "No such file!" && exit
- D1=`date +%s` # seconds since epoch
- [ -z "$D1" ] && echo "Can't get today date" && exit
- for file in $LIST; do
- FDATE=`echo $file | sed -e "s/$FILEPREFIX//"`
- D2=`date +%s -d "$FDATE"`
- SECSOLD=`expr $D1 - $D2`
- DAYSOLD=`expr $SECSOLD / 86400`
- [ "$DAYSOLD" -gt "$AGE" ] && echo "rm -f $DIR/$file" && continue
- echo "# skip $DIR/$file"
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement