1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

feature #575: exec_and_log function accepts a user defined error message

This commit is contained in:
Javi Fontan 2011-04-27 12:02:23 +02:00
parent 9ddf1b5f28
commit 5fa3006adf

View File

@ -83,20 +83,29 @@ function error_message
) 1>&2
}
# Executes a command, if it fails return error message and exits
# Executes a command, if it fails returns error message and exits
# If a second parameter is present it is used as the error message when
# the command fails
function exec_and_log
{
message=$2
output=`$1 2>&1 1>/dev/null`
code=$?
if [ "x$code" != "x0" ]; then
log_error "Command \"$1\" failed."
log_error "$output"
error_message "$output"
if [ -n "$message" ]; then
error_message "$output"
else
error_message "$message"
fi
exit $code
fi
log "Executed \"$1\"."
}
# Like exec_and_log but the first argument is the number of seconds
# before here is timeout and kills the command
#