scope of variable in pipe

后端 未结 6 1493
余生分开走
余生分开走 2020-12-18 10:51

The following shell scrip will check the disk space and change the variable diskfull to 1 if the usage is more than 10% The last echo always shows

6条回答
  •  我在风中等你
    2020-12-18 11:15

    I think you must not be getting to the diskfull=1 line, because if you were, you would get no output at all-- the following exit line would exit the script.

    I don't know why this isn't working, but note that awk can handle the rest of the work:

    diskfull=$(df -HP | grep -vE '^Filesystem|tmpfs|cdrom' | awk 'BEGIN { x = 0 } { if ($5 + 0 >= '$ALERT') { x = 1 } } END { print x }')
    

    This way you don't need the while loop.

提交回复
热议问题