shell practice 03

一转身已万水千山發表於2024-04-12
#!/bin/bash
# author: Chiweiming
# version: v1
# date: 2024-03-26

<<COMMAND
寫一個檢測指令碼,用來檢測本機所有磁碟分割槽讀寫是否正常。
做法:遍歷每一個掛載點,在每一個掛載點新建一個檔案,然後再刪除該檔案,如果一切正常則說明該分割槽沒問題
COMMAND

for path in $(df | grep -v "tmpfs" | sed '1d' | awk '{print $NF}')
do
  touch ${path}/test.txt && rm -f ${path}/test.txt
  if (( $? == 0 )); then
    echo "${path} is nice"
  else
    echo "${path} is error"
  fi
done

相關文章