On Thu, Jan 26, 2006 at 04:10:18PM -0000, Ted Harding wrote:
On 26-Jan-06 Brett Parker wrote:
On Thu, Jan 26, 2006 at 02:36:17PM +0000, Mark Rogers wrote:
If I want to run a script on my externally hosted server to mark me if my disk space is getting low, what's the simplest way to do it?
Hmm, something like...
--- Begin Script #!/bin/bash
filesystem="/" warningpercentage=90 persontomail=me@someplace.com subjectofmail='Warning: You are running low on diskspace!'
percentageused=$(df -h $filesystem | tail -n 1 | awk '{print $5}')
if [[ $percentageused -gt $warningpercentage ]]; then ( echo $nicemessage echo df -h $filesystem ) | mail -s $subjectofmail $persontomail fi
That's surely on the right lines, but since 'df' outputs (e.g.) "91%" and not "91" as the percentage used ("Capacity"), the test will fail (and I don't think "[[" and "]]" will work either).
[[ and ]] definately do work, I tested that bit and everything! (it's a bashism, IIRC, though, hence starting with #!/bin/bash)
However, the following should be OK:
percentageused=$(df -h $filesystem | tail -n 1 | sed 's/%//g' | awk '{print $5}')
Oh soddit, lets go one better :) percentageused=$(df -h / | sed '1d; s#^.* ([0-9]*)%.*$#\1#;')
if [ $percentageused -gt $warningpercentage ]; then ...
Hmm, either works. Test it sometime :)