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

Feature #3574: Create a local version

of the ssh_monitor_and_log function
This commit is contained in:
Jaime Melis 2015-02-20 20:28:39 +01:00
parent 2420cf3aa7
commit 93dee9b9e6

View File

@ -149,6 +149,33 @@ function exec_and_log
fi
}
# This function executes $1 and returns stdout
# If a second parameter is present it is used as the error message when
# the command fails
function monitor_and_log
{
EXEC_OUT=`bash -s 2>/dev/null <<EOF
export LANG=C
export LC_ALL=C
set -xv
$1
EOF`
EXEC_RC=$?
if [ $EXEC_RC -ne 0 ]; then
if [ -n "$2" ]; then
log_error "Command \"$2\" failed: $EXEC_OUT"
else
log_error "Command \"$1\" failed: $EXEC_OUT"
fi
exit $EXEC_RC
fi
echo $EXEC_OUT
}
# Executes a command, if it fails returns error message and exits. Similar to
# exec_and_log, except that it allows multiline commands.
# If a second parameter is present it is used as the error message when