Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/ksh -px
- # get a list of files and dates from ftp and remove files older than ndays
- ftpsite="ftp.debian.org"
- ftpuser="ftp"
- ftppass="ftp"
- putdir="/debian"
- MM=$(TZ=GMT+29 date +%b)
- DD=$(TZ=GMT+29 date +%d)
- echo "removing files older than $MM $DD"
- # get directory listing from remote source
- echo "
- user $ftpuser $ftppass
- binary
- cd $putdir
- ls -l *.txt
- quit" | ftp -i -n $ftpsite | while read line; do
- # line is *each line*, rather than a list of everything
- # helps if the filenames have spaces. Just chomp into $0..
- set -- $line
- # month (element 5), day (element 6) and filename (element 8)
- if (($# > 9)); then
- echo "Can't deal with '$@'"
- continue
- fi
- # check the date stamp
- if [[ $5 == "$MM" ]];
- then
- if (($6 < $DD ));
- then
- # Remove this file
- filename=$8
- echo "Removing $filename"
- # replace the ftp with cat with ftp $ftpsite
- cat <<EOMYF2
- ftp -n -i $ftpsite
- user $ftpuser $ftppass
- binary
- cd $putdir
- delete $filename
- quit
- EOMYF2
- fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement