#!/bin/bash
#chkconfig:35 99 99
#description: Monitor the usage of disk
proc="diskmond"
# test parameters syntax
if [ $# -eq 0 ]
then
echo "参数不正确 例:diskmond [start,restart,stop,status]"
exit 1
fi
function start()
{
if [ -e /var/run/$proc.pid ]
then
echo "磁盘监控程序已经在运行(pid `cat /var/run/$proc.pid`)"
else
echo "磁盘监控程序正在启动中...."
./etc/rc.d/init.d/diskmon &
if [ $? -eq 0 ]
then
pidof -s -x diskmond >/var/run/diskmond.pid
echo "磁盘监控程序启动成功(pid `cat /var/run/$proc.pid`)~"
else
echo "磁盘监控程序发生未知错误,启动失败!"
exit 1
fi
fi
}
function stop()
{
if [ -e /var/run/$proc.pid ]
then
echo "正在停止磁盘监控程序...."
kill -9 `cat /var/run/"$proc".pid`
if [ $? -eq 0 ]
then
echo "磁盘监控程序已经停止"
else
echo "磁盘监控程序停止发生错误(失败)."
fi
rm -f /var/run/$proc.pid
else
echo "磁盘监控程序没有开启"
fi
function status()
{
if [ -e /var/run/$proc.pid ]
then
echo "磁盘监控程序(pid `cat /var/run/${proc}.pid`)正在运行"
else
echo "磁盘监控程序没有开启"
fi
}
function restart()
{
stop
start
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo "参数不正确 例:diskmond [start,restart,stop,status]"
exit 1
;;
esac