Hi all,
i'm a newby in shell script. I have hier a script this will not work with crontab (integer expression expected)
The problem is the Integer comparison "-gt". Whit console the script works fine.
Any idea ?
thanks for any help.
Stefan
Code:sensor_cleandisk() { # grab input variables with sane defaulting LOG_DIR=${1:-} UTC=${2:N} WARN_DISK_USAGE=${3:-1} CRIT_DISK_USAGE=${4:-2} [ ! -d "$LOG_DIR" ] && return 1 CUR_USAGE=$(df -P $LOG_DIR | grep -v -i Dateisystem | awk '{print $5}' | tr -d %) # let's change colour based on severity if [ "$CUR_USAGE" -gt "$CRIT_DISK_USAGE" ]; then USE_COL=${RED} elif [ "$CUR_USAGE" -gt "$WARN_DISK_USAGE" ]; then USE_COL=${YELLOW} else USE_COL=${GREEN} fi echo_msg 1 "disk space currently at ${USE_COL}${CUR_USAGE}%" if [ "$CUR_USAGE" -gt "$CRIT_DISK_USAGE" ] then # grab time in GMT if [ "$UTC" == "Y" ] then TODAY=$(date -u "+%Y-%m-%d") else TODAY=$(date "+%Y-%m-%d") fi cd "$LOG_DIR/dailylogs" # find the oldest directory and exclude today OLDEST_DIR=$(ls | sort | grep -v $TODAY | head -n 1) if [ -z "$OLDEST_DIR" -o "$OLDEST_DIR" == ".." -o "$OLDEST_DIR" == "." ] then echo_msg 1 "${RED}no old log(s) available to clean up" else cd "$OLDEST_DIR" OLDEST_FILE=$(ls -t | tail -n 1) if [ -n "$OLDEST_FILE" ] then echo_msg 1 "removing file: $OLDEST_DIR/$OLDEST_FILE" rm -f $OLDEST_FILE if [ -z "$(ls -t | tail -n 1)" ] then cd .. echo_msg 1 "removing empty dir: $OLDEST_DIR" rmdir "$OLDEST_DIR" fi else cd .. echo_msg 1 "removing empty dir: $OLDEST_DIR" rmdir $OLDEST_DIR fi # run cleandisk again as rm'ing one file might been enough # but we wait 3 secs and hope any open writes are done. sync sleep 3 sensor_cleandisk $LOG_DIR $UTC $WARN_DISK_USAGE $CRIT_DISK_USAGE fi # simple warning (no action taken) of increased disk usage elif [ "$CUR_USAGE" -gt "$WARN_DISK_USAGE" ] then echo_warning_msg 1 "disk space is approaching critical levels" fi }

Reply With Quote
