쉘스크립트 에러 처리
main.sh
#!/bin/bash
check_errs()
{
# Function. Parameter 1 is the return code
# Para. 2 is text to display host.
if [ "${1}" -ne "0" ]; then
echo "ERROR # ${1} : ${2}"
#mail -s "subject here" email@address.com <<< "ERROR # ${1} : ${2}"
exit ${1}
fi
}
. ./exit.sh
check_errs $? $host_name
#!/bin/bash
host_name="test_lb_com"
aa
결과
ERROR # 127 : test_lb_com
./exit.sh: line 3: aa: command not found
Process finished with exit code 127