我正在尝试创建一个脚本,以便在unix FS超过使用的某个%时提醒我。我已经成功创建了脚本,并且能够触发警报到我的电子邮件,但我仍然试图将输出格式化为易于阅读。以下是我的代码:
#!/bin/sh
#****************************************************************************************************************************
#Check all Filesystems and see how much space is being used
#****************************************************************************************************************************
set -x
# Load the .profile for the user
. /home/user/.profile
hostname=`uname -n`
Mail_ID="mail@mail.com"
subject="Check File Systems on $hostname"
dfoutput=/tmp2/user/logs/$hostname/dfoutput.txt
dfcleanoutput=/tmp2/user/logs/$hostname/dfcleanoutput.txt
badfilesizelog=/tmp2/user/logs/$hostname/badfs.txt
limit=70
rm $badfilesizelog
df -g | awk '{if ($1 != "Filesystem") print $1, $4, $7}' > $dfoutput
sed -e 's/%//' -e '/-/d' -e '/.*ora/d' -e '/.*var/d' -e '/.*usr/d' -e '/.*monitor/d' $dfoutput > $dfcleanoutput
cat $dfcleanoutput |
while read var1 var2 var3;
do
if [ $var2 -ge $limit ]
then
printf '%-90s %-50s %50s\n' $var1 $var2 $var3>> $badfilesizelog
fi
done
[ -f $badfilesizelog ] && cat $badfilesizelog | mail -s "$subject" $Mail_ID || echo "Do Nothing"
这是此脚本的电子邮件中的输出:
/dev/fs 70 /apps
host:/disk_test 75 /test_software
host:/schema_backup 71 /schema_backup
正如你所看到的那样,它并没有像我希望的那样对齐所有内容:
/dev/fs 70 /apps
host:/disk_test 75 /test_software
host:/schema_backup 71 /schema_backup
如何让格式化正常工作?我尝试了很多不同的方法,但总是遇到相同的对齐问题。
谢谢
答案 0 :(得分:0)
我能够找到一个使用sendmail而不是邮件的工作解决方案,因为邮件导致了我遇到的格式问题。以下是我使用的内容:
java.util.conncurrent.atomic.AtomicBoolean