问题描述:

i would like to make automatic a function to see when disk space is over 90%....

I know how to use df, but i don´t know how to put it as a script. I would like some help here !

Thanks !

网友答案:

Write your script that checks space, then put it in crontab.

Cron allows you to run commands at a specific time interval, and is exactly what you need to accomplish your goal.

网友答案:

You could use awk:

df | grep -v 'Use%' | awk '{if($5 > 50) print $1 " uses " $5 " of its total space"}'

Sample output:

[[email protected]:~]> df | grep -v 'Use%' | awk '{if($5 > 50) print $1 " uses " $5 " of its total space"}'
/dev/md2 uses 73% of its total space
/dev/sdb4 uses 66% of its total space
网友答案:
#!/bin/bash
_servers="[email protected] [email protected] [email protected]"
_out="/tmp/output.$$"
_email="[email protected]"
_sub="Disk Space Report $(date)"
_ssh=/usr/bin/ssh
_mail=/usr/bin/mail

>$_out
for s in $_servers
do
    $_ssh $s df -H >>$_out
done

$_mail -s "${_sub}" $_email <$_out

Run this from one of your servers which can login to rest of all servers using ssh keys without password. Setup a cron and you are done. If you want output for all server otherwise you can apply for 1 server also.

相关阅读:
Top