开发者

Script about disk space

i would like to make automatic a function to see when disk space is over 90%.... I know how to u开发者_Python百科se 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:

[adrian@cheops3:~]> 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="user1@server1 user2@server2 user3@server12"
_out="/tmp/output.$$"
_email="you@example.com"
_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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜