Advertisement
chatchai_j

rmdaily.sh

Jan 11th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.59 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. FILEPREFIX="dailyfilename_"
  4. AGE=7
  5.  
  6. [ -z "$1" ] && echo  "Usage: $0 DIR\ne.g. : $0 ." && exit
  7.  
  8. DIR="$1"
  9. cd $DIR || { echo "Can't change directory to $DIR"; exit; }
  10.  
  11. LIST=${FILEPREFIX}*
  12. [ -z "$LIST" ] && echo "No such file!" && exit
  13.  
  14. D1=`date +%s`   # seconds since epoch
  15. [ -z "$D1" ] && echo "Can't get today date" && exit
  16.  
  17. for file in $LIST; do
  18.     FDATE=`echo $file | sed -e "s/$FILEPREFIX//"`
  19.     D2=`date +%s -d "$FDATE"`
  20.     SECSOLD=`expr $D1 - $D2`
  21.     DAYSOLD=`expr $SECSOLD / 86400`
  22.     [ "$DAYSOLD" -gt "$AGE" ] && echo "rm -f $DIR/$file" && continue
  23.     echo "# skip $DIR/$file"
  24. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement