#!/bin/bash

LOGFILE="/export/`hostname`.0/schastel/logs/`hostname`_update.log"
mkdir -p `dirname $LOGFILE`

function log() {
    LOGLEVEL=`printf " |%8s |" $1`
    shift
    MESSAGE=$@
    DATE=`date +"%FT%T"`
    echo "$DATE$LOGLEVEL $MESSAGE"  >> $LOGFILE
}

#Disk is either 0, 1, or 2
disk=$1
if [ "$disk" == "" ]; then
    disk=0
    startAt=$1
elif [ "$disk" != "0" ] && [ "$disk" != "1" ] && [ "$disk" != "2" ]; then
    log "ERROR" "Set disk value to 0, 1, or 2. Exiting"
    exit 1
else
    startAt=$2
fi

log "INFO" "Disk=[$disk] / StartAt=[$startAt]"

letters="0 1 2 3 4 5 6 7 8 9 a b c d e f"
for letter1 in $letters; do
    for letter2 in $letters; do
	current=$letter1$letter2
	if [[ "$startAt" > "$current" ]];	then
	    log "INFO" "Table $letter1$letter2 ignored"
	else
	    log "INFO" "Processing table $letter1$letter2"
	    $HOME/dev/FilesMonitoring/NodeRelated/update_table_undefined.py -disk $disk $letter1$letter2 -l 5000 >> $LOGFILE 2>> $LOGFILE
	fi
    done
done

