Re: Calculating folder sizes
Re: Calculating folder sizes
- Subject: Re: Calculating folder sizes
- From: "Laine Lee" <email@hidden>
- Date: Mon, 11 Sep 2006 11:08:07 -0500
On 9/1/06 2:44 AM, "Michael Curtis" <email@hidden> wrote:
> We are moving to a new server that has a terabyte of space. We used
> to use partitions and so it was easy to see when they were filling
> up. Now we are going to use one huge partition I need to run a report
> over the folders to see which ones are growing. I was hoping an
> Applescript would be able to do this and hopefully export the data so
> I can put it into Excel.
Maybe you can use this for starters. Modifying it to send to Excel shouldn't be very difficult.
(*Report Sizes And Monitor Changes
(Tested with 10.4.7 and Server 10.4.7)
To test this script put 4 folders with varying contents in /Library/WebServer/Documents
and name them "post", "fad", "fish", and "42".
Run this as an admin user and enter the admin password when prompted. After the script
is run, examine the contents of the new folder in your home folder named "WebSizeDocs".
Add or remove contents from the 4 previously mentioned folders and run the script again.
Examine the contents of the WebSizeDocs folder again.
*)
property tmpfile : "/tmp/execme"
do shell script "pwd" with administrator privileges
set thismonth to do shell script "date +%m"
set thisdate to do shell script "date +%d"
set file_name to "Sizes_" & thismonth & "-" & thisdate & ".txt"
set size_report to ((path to current user folder) as Unicode text) & "WebSizeDocs:" & file_name
set indiv_report_lead to ((path to current user folder) as Unicode text) & "WebSizeDocs:" & "Sizes_" & thismonth & "-" & thisdate
set size_items_users to {"post", "fade", "fish", "42"}
set biglist to {}
repeat with i in size_items_users
set path2i to (path to startup disk as Unicode text) & ("Library:WebServer:Documents:" & i)
set end of biglist to path2i
end repeat
tell application "Finder"
set startnum to 1
if exists file size_report then
--display dialog size_report
set rename_target to alias size_report
try
set name of rename_target to "Sizes_" & thismonth & "-" & thisdate & "_old_" & startnum & ".txt"
on error
repeat
set startnum to startnum + 1
try
set name of rename_target to "Sizes_" & thismonth & "-" & thisdate & "_old_" & startnum & ".txt"
exit repeat
end try
end repeat
end try
end if
set size_items to biglist
end tell
try
do shell script "mkdir ~/WebSizeDocs"
end try
do shell script "echo" & space & "Today\\'s CustomServer web content size changes:" & return & return & space & ">" & space & "~/WebSizeDocs/" & file_name
set fullreport to ""
set allchanges to ""
try
set the the_report to open for access file size_report with write permission
set the the_report to alias size_report
on error pren
set the the_report to alias size_report
end try
repeat with i in size_items
set the item_info to info for (i as alias)
if name of item_info is not "Sites" then
set itemname to name of item_info
else
tell application "Finder"
set typicaluser to (container of (i as alias) as string)
set typeinfo to info for typicaluser
set itemname to name of typeinfo
end tell
end if
tell application "Finder"
try
set compare_file to (every item of folder (((path to current user folder) as Unicode text) & "WebSizeDocs:" as alias) whose name contains (itemname & "."))
set compare_item to first word of (read (compare_file as file specification)) as integer
do shell script "rm" & space & quoted form of (POSIX path of (compare_file as alias))
set no_compare_item to false
on error
set no_compare_item to true
end try
end tell
set the indiv_report to (indiv_report_lead & "_" & itemname & ".txt")
set path2i to i
try
set item_size to round ((size of the item_info) / 1000) as real
on error
set theShellScript to "osascript -e 'set the item_info to info for (\"" & path2i & "\" as alias)
set size_of_info to size of item_info'"
do shell script "echo" & space & quoted form of theShellScript & space & ">" & space & tmpfile
do shell script "chmod +x" & space & tmpfile
set item_size to do shell script tmpfile with administrator privileges
do shell script "rm" & space & tmpfile
set item_size to round (item_size / 1000) as real
end try
set my_size to ((round item_size / 1000) as text) --& space & "M"
if no_compare_item then
set size_change to (0 as integer)
else
set size_change to ((my_size as integer) - compare_item) & space & "Megs"
end if
set itemname to itemname & ":"
set item_name to itemname & " "
try
set indiv_report_file to open for access file indiv_report with write permission
--display dialog "1"
set the indiv_report_file to alias indiv_report
--display dialog "2"
write my_size & return to indiv_report_file starting at eof
--display dialog "3"
set the indiv_report_file to alias indiv_report
---display dialog "4"
close access indiv_report_file
on error pren
try
close access indiv_report_file
end try
display dialog pren
try
close access indiv_report_file
end try
end try
if size_change is not equal to (0 & space & "Megs") then
write item_name & size_change & return to the_report starting at eof
set allchanges to item_name & size_change & return
end if
set fullreport to fullreport & return & item_name & (my_size as integer)
end repeat
set fullreport to return & "Complete CustomServer web content size listings" & return & return & fullreport
try
write fullreport to the_report starting at eof
on error Frr
display dialog Frr
end try
close access the_report
--
Laine Lee
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden