Low disk space alert bash script

Linux command

========================

cd /home/

vi disk_space_alert.sh

write into this bash script as follows

=========================

#!/bin/bash
#Define Variable
LIMIT='90'
DOMAIN=$(hostname)
DIR='/var/www'
MAILTO='hanamitsu_makoto@number-1.co.jp,saiful_takeshi@number-1.co.jp'
SUBJECT="Disk Usage Alert[$DOMAIN]"
#Command section
cd $DIR
USED=`df . |awk '{print $5}' | sed -ne 2p | cut -d"%" -f1`
DIRLIST=`du -sh ${DIR}/*`
if[ $USED -gt $LIMIT ]
then
 mail -s "$SUBJECT" $MAILTO <<EOF
 Hostname: $DOMAIN
 Your current used disk space is: $USED%
 Directory:${DIR}/*
 Details:
 $DIRLIST
DateTime: $(date)
EOF
fi

==========================

save file commadn

===========

😡

make the file as executable

========================

chmod +x disk_space_alert.sh

run this file

============

sh disk_space_alert.sh

 

 

corntab file

==============

#毎日10時00分に実行する
#ユーザー:root
00 10 * * * root /home/disk_space_alert.sh

 

zip file download 

 

Leave a Reply

Your email address will not be published.