#!/bin/sh # --> get the dir of this script SOURCE="${BASH_SOURCE[0]}" # resolve $SOURCE until the file is no longer a symlink while [ -h "$SOURCE" ]; do DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null && pwd )" SOURCE="$(readlink "$SOURCE")" [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it # relative to the path where the symlink file was located done # --> ensure enough arguments # if [ "$#" -ne 3 ]; then echo $# if (("$#" < 3)) || (("$#" > 4)); then echo "Usage: $0 [--debug]" echo "Ex: $0 \"*\" 1 10" echo "Ex: $0 \"*\" 8 59 --debug" exit fi # --> decide if print debug DEBUG=0 for arg in $* do if [ $arg == "--debug" ]; then DEBUG=1 set -x break fi done # --> add insight cron job INSIGHT_SH=/mnt/ext/opt/HybridBackup/rr2/scripts/insight/insight.sh chmod +x $INSIGHT_SH RUN_SH="$INSIGHT_SH -runall >/dev/null 2>&1" # --> check if having the script already LIST=`crontab -l` if echo "$LIST" | grep -q "$INSIGHT_SH"; then echo "The insight.sh exists already."; else echo "crontab -l | { cat; echo "$1 $2 $3 * * $RUN_SH"; } | crontab -" crontab -l | { cat; echo "$1 $2 $3 * * $RUN_SH"; } | crontab - # echo "crontab /etc/config/crontab" # crontab /etc/config/crontab echo "/etc/init.d/crond.sh restart" /etc/init.d/crond.sh restart crontab -l fi set +x exit 0