Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created July 27, 2015 17:09
Show Gist options
  • Save anonymous/73e1e5b2b863a0726a5c to your computer and use it in GitHub Desktop.
Save anonymous/73e1e5b2b863a0726a5c to your computer and use it in GitHub Desktop.
def get_remote_files(environment, hostname, directory_list, ignore_list)
counter = 0
Net::SSH.start(hostname, USERNAME, :password => PASSWORD) do |ssh|
directory_list.each do |dir|
ssh.exec("find #{dir} -type d -o -type f -exec stat -c '%u, %g, %a, %s, %Y, %n' {} \\;") do |ch, stream, data|
# User ID, Group ID, Access Rights (octal), Total Size (bytes), Last Modified Time (unix timestamp)
data_array = data.split(", ")
file_path = "#{data_array[5]}".gsub("\n", "")
unless ignore_list.any? { |s| file_path.include?(s) } then
hash = "#{file_path}#{data_array[0]}#{data_array[1]}#{data_array[2]}#{data_array[3]}#{data_array[4]}".hash
hash_file(environment, file_path, data_array[0], data_array[1], data_array[2], data_array[3], data_array[4], hash)
#puts "#{hash}, #{dir}, #{data_array[5]}"
#counter += 1
end
counter += 1
end
#ssh.loop
end
end
puts "Finished processing #{counter} remote files on #{hostname}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment