Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #!/bin/bash
  2. site_url="hue:8888"
  3. hdfspath="/master/datalake/2016/11/18"
  4. user="timvw"
  5. pass="xxx"
  6. cookie_path=cookie
  7. target=./data
  8.  
  9. # hue api variables
  10. login_url="$site_url/accounts/login/"
  11. browse_url_prefix="$site_url/filebrowser/view="
  12. browse_url_suffix="?format=json"
  13. download_url_prefix="$site_url/filebrowser/download="
  14.  
  15. # go to the login page and fetch the csrf token
  16. curl -s -b "$cookie_path" -c "$cookie_path" --request GET "$login_url?next=/" -o /dev/null
  17. csrftoken=$(grep csrftoken "$cookie_path" | cut -f 7)
  18. # now login
  19. curl -s -b "$cookie_path" -c "$cookie_path" -d "csrfmiddlewaretoken=$csrftoken&username=$user&password=$pass&next=%2F" "$login_url" -s -o /dev/null
  20.  
  21. #list files
  22. files=$(curl -s -b "$cookie_path" -c "$cookie_path" "${browse_url_prefix}${hdfspath}${browse_url_suffix}" | grep path | grep gz | sed 's/"path": "//g' | sed 's/",//g' | sort | uniq | cut -f 1- -d ' ' --output-delimiter=$'\r\n')
  23.  
  24. for file in $files
  25. do
  26. filepath=$(dirname $file)
  27. filename=$(basename $file)
  28. mkdir -p ${target}${filepath}
  29. curl -s -b "$cookie_path" -c "$cookie_path" "${download_url_prefix}$filepath" -o ${target}${filepath}/${filename}
  30. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement