Script to install monitoring task.
This commit is contained in:
52
tools/monitoring__crontask_install.sh
Executable file
52
tools/monitoring__crontask_install.sh
Executable file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ "$#" != 1 ]]
|
||||||
|
then
|
||||||
|
echo >&2 "usage:"
|
||||||
|
echo >&2 "$0 install"
|
||||||
|
echo >&2 "$0 uninstall"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$1" == "install" ]]
|
||||||
|
then
|
||||||
|
INSTALL=true
|
||||||
|
elif [[ "$1" == "uninstall" ]]
|
||||||
|
then
|
||||||
|
INSTALL=false
|
||||||
|
else
|
||||||
|
echo >&2 "unknown argument : $1"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd -P "$(dirname "$(readlink -f "$0")" )"
|
||||||
|
|
||||||
|
if [[ "$PWD" != "$(printf %q "$PWD" )" ]]
|
||||||
|
then
|
||||||
|
echo >&2 "WARNING: path seems unsafe: $PWD"
|
||||||
|
fi
|
||||||
|
|
||||||
|
SCRIPT_ROOT="$PWD"
|
||||||
|
cd ..
|
||||||
|
INFRA_ROOT="$PWD"
|
||||||
|
|
||||||
|
CRON_LINES=()
|
||||||
|
|
||||||
|
if [[ "$INSTALL" == true ]]
|
||||||
|
then
|
||||||
|
while IFS="" read -u 3 -r MONITOR_SCRIPT_PATH
|
||||||
|
do
|
||||||
|
if [[ "$MONITOR_SCRIPT_PATH" != "$(printf %q "$MONITOR_SCRIPT_PATH" )" ]]
|
||||||
|
then
|
||||||
|
echo >&2 "WARNING: path seems unsafe: $MONITOR_SCRIPT_PATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
CRON_LINES+=( "0 0 * * * $SCRIPT_ROOT/run_and_output_only_on_error.sh $INFRA_ROOT/$MONITOR_SCRIPT_PATH # monitoring_crontask" )
|
||||||
|
|
||||||
|
done 3< <( find */ -iname "monitor_check_once.sh" )
|
||||||
|
fi
|
||||||
|
|
||||||
|
{
|
||||||
|
crontab -l | fgrep -v "# monitoring_crontask"
|
||||||
|
printf '%s\n' "${CRON_LINES[@]}"
|
||||||
|
} | crontab -
|
||||||
22
tools/run_and_output_only_on_error.sh
Executable file
22
tools/run_and_output_only_on_error.sh
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
LOGFILENAME=$(mktemp /tmp/run_and_output_only_on_error_XXXXXX)
|
||||||
|
# set -xv
|
||||||
|
|
||||||
|
trap "rm -f ${LOGFILENAME}" EXIT
|
||||||
|
|
||||||
|
if
|
||||||
|
(
|
||||||
|
$@
|
||||||
|
) > "${LOGFILENAME}" 2>&1
|
||||||
|
then
|
||||||
|
true
|
||||||
|
else
|
||||||
|
echo
|
||||||
|
echo "Error on running: $@"
|
||||||
|
echo
|
||||||
|
echo "Here's the program's output (out and err combined)"
|
||||||
|
cat "${LOGFILENAME}"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user