linux 对文件testfile只读,监控linux文件系统只读性

需求:由于断电故障,会导致虚机文件系统损坏,最后变成read-only的模式,这种情况影响转码虚机的服务。所以对于read-only文件系统,需要在zabbix监控起来,如果发现哪个虚机的文件系统是read-only的,要马上发信报警。

处理方法:可以通过脚本和zabbix实现。

脚本详细如下:

脚本1

#!/bin/sh

testfile="/test.tmp"

touch $testfile >/dev/null 2&>1

if [ -f "$testfile" ] ; then

rm -f $testfile&&echo "1"

else

echo "0"

fi

脚本2

#!/bin/bash

for file in `ls /root`

do

if [ -f $file ];then

filew=`ls -l $file|cut -c 3`

if [ $filew = w ];then

echo "1"

exit 1

else

echo "0"

exit 0

fi

fi

done

#!/bin/sh

declare -a    pid

ro=`mount|awk '{print $6}'|grep ro`

if [ -z $ro ];then

echo "1"

exit 1

else

echo "0"

exit 0

fi

~

3个脚本都可以实现目的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值