Files
gourichon_org/tools/monitoring__crontask_install.sh
Stephane Gourichon 929f22861d Clearer test output.
2025-09-05 22:55:44 +02:00

55 lines
1.0 KiB
Bash
Executable File

#!/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
echo >&2
echo >&2 "Will run: $MONITOR_SCRIPT_PATH"
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 "test_acceptance.sh" )
fi
{
crontab -l | fgrep -v "# monitoring_crontask"
printf '%s\n' "${CRON_LINES[@]}"
} | crontab -