Mac Unit Test part 2: Checking disk space

18 Jun 2006 15:20 - (1) comments

Mac Unit Test part 1: Testing servers and ports

I use the following script to check free disk space.

#!/usr/bin/ruby -w
free_space_str = `/usr/sbin/diskutil info / | grep 'Free Space'`
free_space = free_space_str.slice(/([0-9]|\.)+/)
free_space_bytes = free_space_str.slice(/((G|M|k)B)+/)

free_space = free_space/1000 if free_space_bytes == "MB"
free_space = free_space/1000000 if free_space_bytes == "kB"

if free_space.to_f < $*[0].to_f then
msg = "Free disk space is too low at: " + free_space + free_space_bytes + "\nStarting periodic"
`osascript -l AppleScript -e 'tell Application "Finder" to display dialog "#{msg}" ' `
p msg
`periodic daily weekly`
end

Comments

This one will work remotely as well :-):

#!/usr/bin/ruby -w
$*.unshift '10' if $*.size == 0 # default to 10 Gig
$*.unshift '' if $*.size == 1
server, limit = $*

ssh = server != '' ? "ssh #{server}" : ''

free_space_str = `#{ssh} /usr/sbin/diskutil info / | grep 'Free Space'`
free_space = free_space_str.slice(/([0-9]|\.)+/)
free_space_bytes = free_space_str.slice(/((G|M|k)B)+/)

free_space = free_space/1000 if free_space_bytes == "MB"
free_space = free_space/1000000 if free_space_bytes == "kB"

if free_space.to_f < limit.to_f then
msg = "Free disk space is too low at #{server}: #{free_space} #{free_space_bytes} \nStarting periodic"
`osascript -l AppleScript -e 'tell Application "Finder" to display dialog "#{msg}" ' `
p msg
`#{ssh} periodic daily weekly`
end

On 20 Jun 8:50 by marek

Comments have been closed.

Admin