Advertisement
petesh

rewriting without arrays, line oriented

Feb 25th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.18 KB | None | 0 0
  1. #!/bin/ksh -px
  2. # get a list of files and dates from ftp and remove files older than ndays
  3.  
  4. ftpsite="ftp.debian.org"
  5. ftpuser="ftp"
  6. ftppass="ftp"
  7. putdir="/debian"
  8.  
  9. MM=$(TZ=GMT+29 date +%b)
  10. DD=$(TZ=GMT+29 date +%d)
  11.  
  12. echo "removing files older than $MM $DD"
  13.  
  14.  # get directory listing from remote source
  15. echo "
  16. user $ftpuser $ftppass
  17. binary
  18. cd $putdir
  19. ls -l *.txt
  20. quit" | ftp -i -n $ftpsite | while read line; do
  21.     # line is *each line*, rather than a list of everything
  22.     # helps if the filenames have spaces. Just chomp into $0..
  23.     set -- $line
  24.     # month (element 5), day (element 6) and filename (element 8)
  25.     if (($# > 9)); then
  26.         echo "Can't deal with '$@'"
  27.         continue
  28.     fi
  29.     # check the date stamp
  30.     if [[ $5 == "$MM" ]];
  31.     then
  32.         if (($6 < $DD ));
  33.         then
  34.             # Remove this file
  35.             filename=$8
  36.             echo "Removing $filename"
  37.  
  38.             # replace the ftp with cat with ftp $ftpsite
  39.             cat <<EOMYF2
  40.             ftp -n -i $ftpsite
  41.             user $ftpuser $ftppass
  42.             binary
  43.             cd $putdir
  44.             delete $filename
  45.             quit
  46. EOMYF2
  47.         fi
  48.     fi
  49. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement