![Bash 스크립트는 다른 Ubuntu 버전에서 작동하지 않습니다](https://linux55.com/image/181728/Bash%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EB%8A%94%20%EB%8B%A4%EB%A5%B8%20Ubuntu%20%EB%B2%84%EC%A0%84%EC%97%90%EC%84%9C%20%EC%9E%91%EB%8F%99%ED%95%98%EC%A7%80%20%EC%95%8A%EC%8A%B5%EB%8B%88%EB%8B%A4.png)
하드 드라이브 사용량을 확인하고 사용량이 용량 비율에 도달하면 알림을 보내는 bash 스크립트를 작성했습니다.
#!/bin/bash
Name=$(hostname)
current_usage=$( df -h | grep '/dev/sda5' | awk {'print $5'} )
max_usage=65%
if [ ${current_usage%?} -ge ${max_usage%?} ]; then
mailbody="Hard drive is running out of space at Virtual Machine ${Name}. Current usage: ${current_usage}."
echo ${mailbody} | mail -s "Hard Drive Usage Alert" root
fi
Ubuntu 20.04의 가상 머신에서 실행하면 스크립트가 제대로 작동합니다.
그러나 Ubuntu 18.04에서 실행하는 경우 다음 메시지가 나타납니다.
/etc/cron.daily/df-check:
/etc/cron.daily/df-check: line 7: [: -ge: unary operator expected
왜 이런 일이 발생하는지 아시나요?
감사해요.