쉘 스크립트를 이용한 디스크마운트 체크하기.
안녕하세요. 달소입니다.
이번글은 PBS를 백업서버로 사용할때 백업서버를 이용하는상황에서
백업서버의 부팅시에 nfs가 제대로 연결되지않을시 제대로 백업이 되지않습니다.
그래서 crontab으로 mount 명령어를 간단히 등록해줄까하다가..
혹시나 지속적으로 mount 체크를 해줘야하는부분이 있을까 싶어 스크립트로 만들어보았습니다
내용은 어려운게 없으니 간단히 참고하시면되겠습니다
mount 명령어의 타임아웃은 5초이며 실패/성공시에 mount.log에 시간과 결과가 로그로 남습니다.
vi /root/mount_check.sh
#!/bin/bash today=`date` if ! mountpoint -q /data/PBS_NFS; then echo $today "Not mounted" echo $today "Not mounted" >> mount.log echo $today "Mount try" >> mount.log timeout 5s mount 192.168.1.30:/volume2/Proxmox_PBS /data/PBS_NFS if ! mountpoint -q /data/PBS_NFS; then echo "Mount fail" >> mount.log umount -f /data/PBS_NFS umount -l /data/PBS_NFS fi fi if mountpoint -q /data/PBS_NFS; then echo $today "mounted OK!" echo $today "mounted OK!" >> mount.log fi
아래 명령어를 통해 cron등록도 가능합니다.
1분에 한번씩 체크합니다. ㅎ 맨앞에 *를 0으로 바꾸면 한시간에 한번.
echo "* * * * * root sh /root/mount_check.sh" >> /etc/crontab service cron restart
1분단위로 체크하다가 붙으면 아래처럼 됩니다