Advertisement
Guest User

Untitled

a guest
Jul 27th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. def get_remote_files(environment, hostname, directory_list, ignore_list)
  2. counter = 0
  3. Net::SSH.start(hostname, USERNAME, :password => PASSWORD) do |ssh|
  4. directory_list.each do |dir|
  5. ssh.exec("find #{dir} -type d -o -type f -exec stat -c '%u, %g, %a, %s, %Y, %n' {} \\;") do |ch, stream, data|
  6. # User ID, Group ID, Access Rights (octal), Total Size (bytes), Last Modified Time (unix timestamp)
  7. data_array = data.split(", ")
  8. file_path = "#{data_array[5]}".gsub("\n", "")
  9. unless ignore_list.any? { |s| file_path.include?(s) } then
  10. hash = "#{file_path}#{data_array[0]}#{data_array[1]}#{data_array[2]}#{data_array[3]}#{data_array[4]}".hash
  11. hash_file(environment, file_path, data_array[0], data_array[1], data_array[2], data_array[3], data_array[4], hash)
  12. #puts "#{hash}, #{dir}, #{data_array[5]}"
  13. #counter += 1
  14. end
  15. counter += 1
  16. end
  17. #ssh.loop
  18. end
  19. end
  20. puts "Finished processing #{counter} remote files on #{hostname}"
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement