下面的脚本没有按预期工作。Zenity GUI 窗口在我执行时根本没有弹出。我无法找出我在哪里犯了错误。
相同的脚本在 RedHat 中显示 Zenity 结果。
export XAUTHORITY=/home/local/$primaryuser/.Xauthority
ALERT=10
df -h|grep -i dev|grep -vE '^Filesystem|proc|none|tmpfs|udev' |awk '{print $1 " " $5 " " $6}' |while read output
do
partition=$(echo $output | awk '{print $1}')
usage=$(echo $output | awk '{ print $2}' | cut -d'%' -f1)
filesystem=$(echo $output | awk '{print $3}')
if [ $usage -gt $ALERT ]
then
DISPLAY=:0.0 zenity --question --title "$partition is almost full" --text "Do you want to check the highly space utiized files ?"
if [ $? == 0 ]
then
find / -xdev -type f -ls|sort -nrk 7 |head -15 2>/dev/null |DISPLAY=:0.0 zenity --text-info --title "Top 15 disk space utilized files" --width 1000 --height 500
else
DISPLAY=:0.0 zenity --info --text "Details sent to your Inbox in email"
mailx -s "MailAlert: $partition ($filesystem) is running out of diskspace in `hostname`." $primaryuser << EOF
$filesystem usage is $usage% .Please find the below details to identify which files are utilizing high diskspace and take necessary actions.
`find $filesystem -xdev -type f -ls|sort -nrk 7|head -15 2>/dev/null`
SYSTEM INFO:
$hardware
You are receiving this email because $primaryuser appears to be the primary user of `hostname`.If you have already reduced the diskspace you can ignore this message.
EOF
fi
else
exit 1
fi
done