I would actually rearrange the code so that the test immediately follows the command. Note how you can just include a command in an
if statement to test its success or failure:
Code:
#!/usr/bin/ksh
set -x
HOSTNAME=$(hostname)
fs=$(df| awk '/testfs/{print $7}')
if [ -z "$fs" ]; then
echo "Mounting filesystem..."
if mount /testfs; then
mail -s "Filesystem mounted with success" "xxx@email1 yyy@email2"</var/log/succes.err >/dev/null
else
mail -s "Cannot mount filesystem for $HOSTNAME" "xxx@email1 yyy@email2"</var/log/fail.err >/dev/null
exit 1
fi
else
mail -s "No such filesystem exists on $HOSTNAME" "xxx@email1 yyy@email2"</var/log/miss.err >/dev/null
exit 2
fi