Last active
February 25, 2016 06:19
-
-
Save tridevgurung/1f97ce15004f5d43d2e1 to your computer and use it in GitHub Desktop.
Dispatching script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
APPNAME="appfolder" | |
FILE_EXTENSION='.gte' | |
MOUNT_POINT="/media/hdd" | |
APP_PATH="$MOUNT_POINT/$APPNAME" | |
TMP_DIR="/tmp/$APPNAME/fohor" | |
TMP_DIR_CHUNKS="/tmp/$APPNAME/fohor/chunks" | |
USERS_DIR="$APP_PATH/workers" | |
INPUT_DIR="$APP_PATH/inputs" | |
REPORTS_DIR="$APP_PATH/reports" | |
mkdir -p $TMP_DIR $TMP_DIR_CHUNKS | |
rm -rf $TMP_DIR_CHUNKS/* | |
#for template name on report only | |
today=$(date +%m_%d_%Y) | |
REPORT_FILE=report_$today | |
mkdir -p $REPORTS_DIR | |
#remove previously created csv file for the day (if exists any) | |
rm -rf $REPORTS_DIR/$REPORT_FILE.csv | |
#listing the users and inputs in file (its all temp file) | |
ls $USERS_DIR > $TMP_DIR/users.list | |
#ls $INPUT_DIR > $TMP_DIR/inputs.list | |
(cd $INPUT_DIR && cat batchManifest.csv | cut -d ',' -f2 | sed 1d) > $TMP_DIR/inputs.list | |
pwd | |
#counting the user_numbers and input files | |
users_count=`wc -l $TMP_DIR/users.list|awk '{print $1}'` | |
inputs_count=`wc -l $TMP_DIR/inputs.list|awk '{print $1}'` | |
#ROUND ROBIN in shell-logic | |
i=1 | |
while read line; do | |
if [ $i -le $users_count ]; then | |
echo $line >> $TMP_DIR_CHUNKS/$i | |
elif [ $i -gt $users_count ];then | |
i=1 | |
echo $line >> $TMP_DIR_CHUNKS/$i | |
fi | |
# echo $i | |
let i=$i+1 | |
done < $TMP_DIR/inputs.list | |
#listing all the chunks and users in ARRAY :D | |
files_to_move=( `ls -1 $TMP_DIR_CHUNKS` ) # => ( 1 10 11 12 ... 2 20 21 22 ... 9) | |
users_to_move_into=(` ls -1 $USERS_DIR` ) # => ( abishek abishek2 annad ... yamuna ) | |
#some fancy outputs | |
echo "working division started for $today" | |
echo "populating files for: "; | |
#main loop on script | |
for (( i=0; i < $users_count; i++)); do | |
echo -e "\t${users_to_move_into[$i]}"; | |
# cp "$TMP_DIR_CHUNKS/${files_to_move[$i]}" "$USERS_DIR/${users_to_move_into[$i]}"; | |
echo -e "${users_to_move_into[$i]},`cat $TMP_DIR_CHUNKS/${files_to_move[$i]}|tr '\n' ,`" >> $REPORTS_DIR/$REPORT_FILE.csv | |
while read line;do | |
# mv -fv "$INPUT_DIR/$line" "$USERS_DIR/${users_to_move_into[$i]}/untagged/$line"; | |
filename="${line%.*}" | |
#mv -v $INPUT_DIR/$filename.{xef,bin,gte} "$USERS_DIR/${users_to_move_into[$i]}/untagged/"; | |
mv -v $INPUT_DIR/*$filename* "$USERS_DIR/${users_to_move_into[$i]}/untagged/"; | |
# mv -v $INPUT_DIR/$filename.gte "$USERS_DIR/${users_to_move_into[$i]}/untagged/"; | |
echo | |
done < "$TMP_DIR_CHUNKS/${files_to_move[$i]}" | |
done | |
#Script creation date and time | |
#Fri Feb 27 01:51:25 NPT 2015 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment