Advertisement
Guest User

Untitled

a guest
Sep 30th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.50 KB | None | 0 0
  1. ###
  2. #
  3. # full script contains a locking mechanism, you should implement that if you want to use it
  4. #
  5. ###
  6.  
  7. #!/bin/bash
  8. # ------------------------------------------------------------------------------
  9. # File:    wget_cdn_logs
  10. # Descrip: transfers all files from the ftp which are not in a file which
  11. #          contains a list of already transfered/processed files so that we
  12. #          are able to delete files after processing (to avoid reprocessing)
  13. #
  14. # Usage:   wget_cdn_logs
  15. #
  16. # Project: XXX
  17. #
  18. # Update:  2011-08-05 TS-MMS/joko: (initial)
  19. # KnownErrors/ToDos:
  20. #
  21. # ------------------------------------------------------------------------------
  22.  
  23.  
  24. WORKING_DIR="/store/urchin/logs/cdn"
  25. DOWNLOADED_FILELIST="${WORKING_DIR}/.files_done"
  26. DOWNLOAD_FILELIST="${WORKING_DIR}/.downloadlist"
  27.  
  28. # this is also hardcoded down in a sed because of the nice /...
  29. FTP_ADDR="ftp://upload.xxx.de/"
  30. FTP_USER="xxx-logfile"
  31. FTP_PASS="xxx"
  32.  
  33.  
  34. ###
  35. #
  36. # Main Code
  37. #
  38. ###
  39.  
  40. cd ${WORKING_DIR} 2>/dev/null
  41. if [ "$?" != "0" ]; then echo "working dir does not exist" 1>&2; exit 1; fi
  42.  
  43. # remove the wget ftp listing if there is one, some wget versions have a bug
  44. # which always appends to existing .listing files
  45. rm .listing 2>/dev/null
  46.  
  47. # now download only the listing (by rejecting every real file), we will use
  48. # this to determine what we haven't already downloaded from the ftp
  49. wget --quiet --no-remove-listing --recursive --level=0 --no-directories --ftp-user=${FTP_USER} --ftp-password=${FTP_PASS} --reject "*" "${FTP_ADDR}*"
  50.  
  51. # now we edit the .listing file to our needs, we only need the last column
  52. # and we want to prepend everything with the FTP_ADDR
  53. ## we could do this inline with --i but the second wget will overwrite our
  54. ## .listing which we still need as the new list of already dled files
  55. sed -n 's/.* /ftp:\/\/upload.xxx.de\//;p' .listing > .listing_transformed
  56.  
  57. # now calculate the diff of the listing and of the file list of dled files the
  58. # output is what needs to be download
  59. comm -23 .listing_transformed ${DOWNLOADED_FILELIST} > ${DOWNLOAD_FILELIST}
  60.  
  61. # now wget everything that is in the downloadlist
  62. wget --quiet --recursive --level=0 --continue --no-directories --ftp-user=${FTP_USER} --ftp-password=${FTP_PASS} --input-file=${WORKING_DIR}/.downloadlist
  63.  
  64. # if the download was successful then update list of downloaded files
  65. if [ "$?" -eq "0" ]; then
  66.         cp .listing_transformed ${DOWNLOADED_FILELIST}
  67. fi
  68.  
  69. # now cleanup some stuff
  70. rm .listing_transformed .listing .downloadlist 2>/dev/null
  71.  
  72. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement