#!/usr/bin/ksh
WORKFILE="/tmp/df.work" # Holds filesystem data
>$WORKFILE # Initialize to empty
OUTFILE="/tmp/df.outfile" # Output display file
>$OUTFILE# Initialize to empty
EXCEPTIONS="/usr/local/bin/exceptions" # Override data file
DATA_EXCEPTIONS="/tmp/dfdata.out" # Exceptions file w/o # rows
THISHOST=`hostname`# Hostname of this machine
MIN_MB_FREE="50MB" # Min. MB of Free FS Space
function check_exceptions
{
# set -x # Uncomment to debug this function
while read FSNAME FSLIMIT
do
# Do an NFS sanity check
echo $FSNAME | grep ":" >/dev/null /
&& FSNAME=$(echo $FSNAME | cut -d ":" -f2)
if [[ ! -z "$FSLIMIT" && "$FSLIMIT" != '' ]]
then
(( FSLIMIT = $(echo $FSLIMIT | sed s/MB//g) * 1024 ))
if [[ $FSNAME = $FSMOUNT ]]
then
# Get rid of the "MB" if it exists
FSLIMIT=$(echo $FSLIMIT | sed s/MB//g)
if (( $FSMB_FREE < $FSLIMIT ))
then
return 1 # Found out of limit
else
return 2 # Found OK
fi
fi
fi
done < $DATA_EXCEPTIONS # Feed the loop from the bottom!!!
return 3 # Not found in $EXCEPTIONS file
}
######## START OF MAIN #############
if [[ -s $EXCEPTIONS ]]
then
# Ignore all line beginning with a pound sign, #
# and omit all blank lines
cat $EXCEPTIONS | grep -v "^#" | sed /^$/d > $DATA_EXCEPTIONS
fi
# Get the data of interest by stripping out the
# /cdrom row and keeping columns 1, 4 and 6
df -k | tail +2 | egrep -v '/cdrom' /
| awk '{print $1, $4, $6}' > $WORKFILE
# Format Variables for the proper MB value
(( MIN_MB_FREE = $(echo $MIN_MB_FREE | sed s/MB//g) * 1024 ))
# Loop through each line of the file and compare column 2
while read FSDEVICE FSMB_FREE FSMOUNT
do
if [[ -s $EXCEPTIONS ]]
then
check_exceptions
RC="$?"
if [ $RC -eq 1 ] # Found out of exceptions limit
then
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
echo "$FSDEVICE mounted on $FSMOUNT only has ${FS_FREE_OUT}MB Free" /
>> $OUTFILE
elif [ $RC -eq 2 ] # Found in exceptions to be OK
then # Just a sanity check - We really do nothing here...
# The colon, :, is a NO-OP operator in KSH
: # No-Op - Do Nothing!
elif [ $RC -eq 3 ] # Not found in the exceptions file
then
FSMB_FREE=$(echo $FSMB_FREE | sed s/MB//g) # Remove the "MB"
if (( $FSMB_FREE < $MIN_MB_FREE ))
then
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
echo "$FSDEVICE mounted on $FSMOUNT only has ${FS_FREE_OUT}MB Free" /
>> $OUTFILE
fi
fi
else # No Exceptions file use the script default
FSMB_FREE=$(echo $FSMB_FREE | sed s/MB//g) # Remove the "MB"
if (( $FSMB_FREE < $MIN_MB_FREE ))
then
(( FS_FREE_OUT = $FSMB_FREE / 1000 ))
echo "$FSDEVICE mounted on $FSMOUNT only has ${FS_FREE_OUT}MB Free" /
>> $OUTFILE
fi
fi
done < $WORKFILE
if [[ -s $OUTFILE ]]
then
echo "/nFull Filesystem(s) on $THISHOST/n"
cat $OUTFILE
print
fi
分享到:
相关推荐
主要介绍了shell脚本实现服务器进程监控的方法,非常不错,具有参考借鉴价值,需要的朋友参考下吧
Linux常用的系统监控shell脚本
主要介绍了本地文件与服务器文件同步shell脚本的方法,然后在文章给大家补充介绍了shell脚本备份本地服务器的文件到远程服务器的实例代码,需要的朋友可以参考下
Linux下监控磁盘的空闲空间的shell脚本,对于系统管理员或DBA来说,必不可少。下面是给出的一个监控磁盘空间空间shell脚本的样本,供大家参考。 1、监控磁盘的空闲空间shell脚本 robin@SZDB:~/dba_scripts/...
shell脚本生成.txt数据文件,shell脚本生成.txt数据文件
通过A服务器自动登录其他服务器自动传输文件、删除文件、自动检测tomcat启动状态,控制启动和停止、可配置多条服务器进行同步处理,适合集群管理
shell脚本,通过snmp方式获取远程服务器的CPU内存和硬盘的使用率,需要支持snmpget和snmpwalk命令,并且为了支持小数运算,需要安装bc命令。
比如,你可以使用shell脚本的PID在/tmp下创建一个唯一的临时文件。有时侯脚本需要检测所有运行的进程,它可以从进程列表中排除自身的子shell。 在bash中,子shell进程的PID存储在一个特殊的变量‘$$’中。这个变量...
使用Shell脚本对Linux系统和进程资源进行监控.docx使用Shell脚本对Linux系统和进程资源进行监控.docx
Shell脚本定时监控tomcat,服务挂掉自动重启
使用 Bash shell 脚本进行功能测试
需要提高cpu利用率的shell脚本
主要介绍了shell脚本实现linux系统文件完整性检测,本文给出的脚本使用对比MD5的方法,检测linux系统文件是否被替换等问题,需要的朋友可以参考下
linux shell脚本获取时间判断时间差,进行计算,自动化
shell编写的采集系统主机信息的脚本,包括CPU,内存,磁盘,网络信息。可以自己设置采集频率,并将采集信息生成SQL脚本通过FTP自动上传至数据库服务器,入库。
该程序使用场景说明:主要用域Linux服务器监控程序日志,如出现关键字异常则触发相应的动作或告警操作,通知到邮件联系人
实战Linux Shell编程与服务器管理的脚本文件和数据文件
本文介绍如何将本地服务器上的gitlba备份文件,备份到远程服务器上面,同时对远程服务器上面的gitlab备份文件进行定时清理。
让Android系统或Android应用执行shell脚本,方法一是:通过修改/system/init/init.c,在里面写入执行脚本的命令。方法二是:启动一个服务,让这个服务去执行脚本。
linux 批量解压文件shell脚本 教程:https://www.bilibili.com/video/BV1Zi4y1C7rL?spm_id_from=333.999.0.0