想更進(jìn)一步提高效率,你不會(huì)想只是坐在你的電腦前手動(dòng)執(zhí)行這些腳本。相反,你會(huì)使用 cron 來(lái)調(diào)度這些任務(wù)周期性地執(zhí)行,并把結(jié)果通過(guò)郵件發(fā)動(dòng)給預(yù)先指定的接收者,或者將它們保存到使用 web 瀏覽器可以查看的文件中。
下面的腳本(filesystem_usage.sh)會(huì)運(yùn)行有名的 df -h 命令,格式化輸出到 HTML 表格并保存到 report.html 文件中:
#!/bin/bash
#演示使用 shell 腳本創(chuàng)建 HTML 報(bào)告的示例腳本
#Web directory
WEB_DIR=/var/www/html
# A little CSS and table layout to make the report look a little nicer
echo"
.titulo{font-size: 1em; color: white; background:#0863CE; padding: 0.1em 0.2em;}
table
{
border-collapse:collapse;
}
table, td, th
{
border:1px solid black;
}
"> $WEB_DIR/report.html
#Viewhostnameand insert it at the top of the html body
HOST=$(hostname)
echo"Filesystem usage for host $HOST
Last updated: $(date)
Filesystem
Size
Use %
">> $WEB_DIR/report.html
#Read the output of df-h line by line
while read line;do
echo"">> $WEB_DIR/report.html
echo $line | awk '{print $1}'>> $WEB_DIR/report.html
echo"
">> $WEB_DIR/report.html
echo $line | awk '{print $2}'>> $WEB_DIR/report.html
echo"
">> $WEB_DIR/report.html
echo $line | awk '{print $5}'>> $WEB_DIR/report.html
echo"
">> $WEB_DIR/report.html
done<<(df-h |grep-vi filesystem)
echo"
">> $WEB_DIR/report.html
在我們的 RHEL 7 服務(wù)器(192.168.0.18)中,看起來(lái)像下面這樣:
服務(wù)器監(jiān)視報(bào)告
你可以添加任何你想要的信息到那個(gè)報(bào)告中。添加下面的 crontab 條目在每天下午的 1:30 運(yùn)行該腳本:
3013***/root/scripts/filesystem_usage.sh
2015職稱計(jì)算機(jī)考試書PowerPoint2007中 .. 定價(jià):¥45 優(yōu)惠價(jià):¥42 更多書籍 | |
2015年全國(guó)職稱計(jì)算機(jī)考試教材(2007模 .. 定價(jià):¥225 優(yōu)惠價(jià):¥213 更多書籍 |