shell脚本练习三

检测脚本,检测本机所有磁盘分区读写是否都正常

(可以遍历所有挂在点,然后新建一个测试文件,再删除测试文件,若可以正常新建和删除,说明分区没问题。)

#!/bin/bash
#version:1t
#author:tongby
#date: 2023-10-13
for mount_p in `df |sed '1d' |grep -v 'tmpfs' |awk '{print $NF}'`
do
    touch $mount_p/testfile && rm -f $mount_p/testfile
    if [ $? -ne 0 ]
    then
        echo "$mount_p 读写出现问题"
        echo "$mount_p 读写正常"
    fi
done

在挂在点创建文件再删除文件过程无误则正常。 

df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.7M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   18G  6.7G   11G  38% /
/dev/sda1                497M  131M  367M  27% /boot
tmpfs                     98M     0   98M   0% /run/user/0
df |sed '1d' |grep -v 'tmpfs' |awk '{print $NF}
/
/boot

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值