Created
December 10, 2010 15:24
-
-
Save kschiess/736328 to your computer and use it in GitHub Desktop.
Gathers key information about a directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/csw/bin/ruby | |
directory = ARGV.join(' ') | |
count = ['?', '?'] | |
# get users, which have created files in dir | |
# | |
users = Hash.new(0) | |
`tree -u '#{directory}'`.split("\n").each do |line| | |
user = line.scan(/\[([^\]]*)\]/).flatten.first | |
if user | |
user = user.strip | |
users[user] += 1 | |
end | |
if md=line.match(/(\d+) director(?:y|ies), (\d+) files?/) | |
count = md[1..2] | |
end | |
end | |
# get usage of directory | |
usage = `du -sh '#{directory}'`.chomp | |
# find the newest file | |
cmd = %Q{ | |
find #{directory} -type f | | |
ruby -n -e'print $_.gsub(/([^A-Za-z0-9_\\-.,\:\\/\@\\n])/n) { "\\\\#\$1" }' | | |
xargs ls -lrtE #{directory} | tail -1 | |
} | |
# puts cmd | |
newest = `#{cmd}` | |
date = '???' | |
if md=newest.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/) | |
date = md[0] | |
end | |
printf "%-28s %3s %3s %s %s\n", | |
usage, | |
count.first, | |
count.last, | |
date, | |
users.map{|u| "#{u.first}(#{u.last.to_s}) " } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment