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).
However, the following should be OK:
percentageused=$(df -h $filesystem | tail -n 1 | sed 's/%//g' | awk '{print $5}')
if [ $percentageused -gt $warningpercentage ]; then ...
Best wishes, Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) Ted.Harding@nessie.mcc.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 26-Jan-06 Time: 16:10:15 ------------------------------ XFMail ------------------------------