commit - aef1742de053a863854a0ec6ecdb2e500a045dd9
commit + 23c8c9a930a6532b06ce5059e8702389d0b0d19e
blob - 406749d961f6a0b69278f95f23d8b7b3f18921f1
blob + cb42a354aedfbb3ca532f9f7584712ee57da0a5c
--- vdcron
+++ vdcron
TEMP=$(mktemp)
FILE=
VERSION=0.7.1
-USAGE="$0 <options>
+CONTEXT="cli"
+USAGE="$0 <options> [context]
options are:
-h : this help
-d : debug
-s <value>: force an initial sleep different than the default: $SLEEP seconds
-f <file> : use a specific input file
-
+ context:
+ Context is just an optional name allowing you to to retreive this information in the logs.
+ This is useful just to know what has been trigered vdcron (cron, apm-resume, ...)
+ By default the value is \"cmd line\"
You are running $0 version $VERSION
"
PARAMS="hdf:s:"
d) DEBUG=1
;;
f) FILE=$OPTARG
+ if [ ! -f "$FILE" ]; then
+ echo "Not a valid file: $FILE"
+ exit 1
+ fi
;;
s) SLEEP=$OPTARG
+ if [ ! "$SLEEP" -gt "0" ]; then
+ echo "Not a valid sleep value: $SLEEP"
+ exit 1
+ fi
;;
h) echo "$USAGE"
exit 0
;;
+ \?) #echo "Invalid argument: $OPTARG"
+ exit 1
+ ;;
+ :)
+ echo "Option $OPTARG requires an argument."
+ exit 1
+ ;;
esac
done
+shift $((OPTIND-1))
+[ -n "$*" ] && CONTEXT="$*"
+
if [ $(id -u) -eq 0 ]; then
[ ! -n "$FILE" ] && FILE="/etc/vdcron.conf"
LOG="/var/log/vdcron.log"
mkdir -p "$(dirname "$LOG")" && touch "$LOG"
fi
-if [ ! -f "$FILE" ]; then
- echo "Your config file $FILE is not found"
- echo "Your config file $FILE is not found" >> "$LOG"
- exit 1
-fi
-
-
if date --version >/dev/null 2>&1 ; then
[ $DEBUG ] && echo Using GNU date
GNU_DATE=1
fi
}
-echo -n "Starting at ..." >> "$LOG"
+echo -n "Starting by -- $CONTEXT -- at ..." >> "$LOG"
sleep $SLEEP
echo " $(date)" >> "$LOG"