Skip to content

Instantly share code, notes, and snippets.

@Monsterovich
Last active July 8, 2017 15:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Monsterovich/ed2a01128279d0fd4c137441d16210a6 to your computer and use it in GitHub Desktop.
Save Monsterovich/ed2a01128279d0fd4c137441d16210a6 to your computer and use it in GitHub Desktop.
This script runs scgb groups (v4)
#!/bin/bash
scgbdir='/mnt/srvdata/server/scgb-hosts/'
botexe=$scgbdir'main/scgb.py'
config='/config.py'
groupsfile='groups.txt'
time=120
txtpath=$scgbdir''$groupsfile
function update_groups {
cp $txtpath $txtpath'.tmp'
readarray -t clients < $txtpath'.tmp'
}
update_groups
update_num=true
while true
do
if [ "$update_num" = true ] ; then
n=$(wc -l < $txtpath)
n=$((n+1))
echo 'Amount of groups:'$n
update_num=false
fi
for ((index=0;index<n;index++))
do
if comm -3 <(sort $txtpath) <(sort $txtpath'.tmp') | grep -q '.*'; then
update_groups
update_num=true
echo 'Group list updated! Restarting...'
break
fi
if [ "${clients[index]}" == "" ];
then
echo "Skipping client #${index}"
sleep $(bc -l <<< $time'/'$n)
continue
fi
client=$scgbdir''${clients[index]}
cd $client
echo 'Processing client: '${clients[index]}
#echo $client'/updates.log'
timeout -s 10 60s python3 $botexe $client''$config >> $client'/updates.log'
echo 'Done! (Status:'$?')'
sleep $(bc -l <<< $time'/'$n)
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment