-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·51 lines (40 loc) · 954 Bytes
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
script=$1
file=$2
if [ -z "$script" ]
then
read -p "Name of script:" script;
fi
if [ -z "$file" ]
then
read -p "File name in /data:" file;
fi
export FILE=$file
export SCRIPT=$script
export Y='\033[0;33m'
export G='\033[0;32m'
export R='\033[0;31m'
export N='\033[0m'
# Total number of lines in file
filelines=$(wc -l < /data/files/$FILE)
# Number of chunks in the array
split=$SPLIT
# Loop counter
counter=0
# Figures out skip based on lines and split
loopSize=$(($filelines / $split + 1))
# +1 because arrays start a 0 and sed starts at 1
start=1
end=($SPLIT + 1)
chunkList=[]
while [ $counter -lt $loopSize ]; do
let counter++
echo -e "$Y Loop[$counter/$loopSize] Loop Size[$split] $N"
sedEnd="${end}p"
# Chunk into array
chunkList="$(sed -n $start,$sedEnd < /data/files/$FILE)"
# Run in Parallel
parallel /data/scripts/$SCRIPT {} ::: ${chunkList[@]}
start=$(($end + 1))
end=$(($end + $split))
done