Mac Unit Test part 2: Checking disk space
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