[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] Re: Simple bash question
Doctor Who wrote:
>> Just curious how this might be accomplished with a bash script. If
>> there was an error kicked back at any step, it would be nice to say as
>> such.
Some advice on the error checking. Create a bash function like
function error_exit {
echo -e "scriptname.sh: $1" 1>&2
exit 1
}
and then use the OR operator to run this if any command fails. For example
e2fsck -f -p /dev/sda1 || echo "$LINENO: Error $? encountered while
checking linux filesystem, continuing anyway"
resize2fs -p /dev/sda1 || error_exit "$LINENO: Couldn't expand linux
filesystem"
$LINENO is the current line number and $? is the exit status of the last
command. I hope that helps.
-Brian