[ale] Re: Simple bash question
Brian Pitts
brian at polibyte.com
Mon Jan 28 21:25:40 EST 2008
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
More information about the Ale
mailing list