Add disk usage. need to fix change_directory function
This commit is contained in:
@@ -51,4 +51,21 @@ module ApplicationHelper
|
||||
return volumes
|
||||
end
|
||||
|
||||
def files(dir)
|
||||
files = Array.new
|
||||
file = Hash.new
|
||||
output = `ls #{dir} -l`.split("\n")
|
||||
output.each do |t|
|
||||
next if t.equal? output.first
|
||||
s = t.split(" ")
|
||||
file["auth"] = s[0]
|
||||
file["size"] = s[4]
|
||||
file["date"] = s[5] + " " + s[6] + " " + s[7]
|
||||
file["name"] = s[8]
|
||||
files << file
|
||||
file = Hash.new
|
||||
end
|
||||
return files
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,3 +1,28 @@
|
||||
module HomeHelper
|
||||
|
||||
def get_du(dir)
|
||||
du = Array.new
|
||||
du_each = Hash.new
|
||||
command = String.new
|
||||
if dir.eql? "/"
|
||||
command = "sudo df /"
|
||||
s = `#{command}`.split("\n")[1].split(" ")
|
||||
avail = s[2].to_f + s[3].to_f
|
||||
else
|
||||
command << "sudo du -s #{dir}"
|
||||
avail = `#{command}`.split(" ")[0].to_f
|
||||
end
|
||||
|
||||
command << "sudo du -s #{dir}/*"
|
||||
puts command
|
||||
output = `#{command}`.split("\n")
|
||||
output.each do |t|
|
||||
du_each['usage'] = t.split(" ")[0].to_f / avail
|
||||
du_each['file_name'] = t.split(" ")[1].split("/").last
|
||||
du << du_each
|
||||
du_each = Hash.new
|
||||
end
|
||||
return du
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user