Linux脚本显示不必要的文件

时间:2017-10-25 04:56:16

标签: linux unix cron

我编写了以下脚本,当我运行它时会显示一些不必要的文件。我只想执行命令并仅接收警报。 脚本如下

 df -h | nawk '/backup/ {print $5 " "  $6}' | while read line;
  do
        usep=$(echo  $line | nawk  '{printf "%d", $1}' )    
        partition=$(echo $line | nawk '{print $2}')
        if (( $usep >= 90)); then
                 echo "$partition ($usep%)" | mailx -s "172.27.68.101" 0234343456@alert.abc.lk;
                echo  "$partition ($usep%)" | mailx -s "172.27.68.101" amalw@abc.lk;
        echo  "$partition ($usep%)" | mailx -s "172.27.68.101" amalw@abc.lk;
        fi
  done

Follwing图像显示输出问题

Matrix Digital Rain

如何在不打开此类目录的情况下将多个收件人添加到此脚本?

2 个答案:

答案 0 :(得分:3)

要将多行bash代码粘贴到终端中,请在行周围添加括号,否则每个行在粘贴后立即作为单独的命令运行:

(df -h | nawk '/backup/ {print $5 " "  $6}' | while read line; do
    usep=$(echo  "$line" | nawk  '{printf "%d", $1}')
    partition=$(echo $line | nawk '{print $2}')
    if(("$usep" >= 90)) ; then echo "$partition ($usep%)" | mailx -s "172.27.68.101" 0234343456@alert.abc.lk;
        echo  "$partition ($usep%)" | mailx -s "172.27.68.101" amalw@abc.lk;
        echo  "$partition ($usep%)" | mailx -s "172.27.68.101" amalw@abc.lk;
    fi
done)

答案 1 :(得分:0)

首先命令df -h|grep backup|sed 's/\%//g'|awk '$5 >= 90 {print $5"% "$6}'使FS( Partition )的使用率超过90%。  其余的命令来提醒邮件。然后:

df -h|grep backup|sed 's/\%//g'|awk '$5 >= 90 {print $5"% "$6}'|while read USAGE PARTITION do echo "$PARTITION ($USAGE)"|mailx -s "172.27.68.101" "0234343456@alert.abc.lk,amalw@abc.lk" done