Skip to content

Instantly share code, notes, and snippets.

@hannesa2
Created January 8, 2023 18:24
Show Gist options
  • Save hannesa2/b36da27d5c1bacdd547d9936b23895ac to your computer and use it in GitHub Desktop.
Save hannesa2/b36da27d5c1bacdd547d9936b23895ac to your computer and use it in GitHub Desktop.
#!/bin/bash
currenttime=$(date +%H:%M)
calendarWeek=~/$(date +%Y_%V)
USAGE=0
INTERVAL=1
ERLAUBT=350
ZUVIEL=350
BASEDIR=$(dirname "$0")
if [[ "$currenttime" > "16:30" ]] && [[ "$currenttime" < "20:00" ]]; then
echo "Minecraft accepted $currenttime"
else
ps -aux | grep -e minecraft | grep vincent | awk '{print $2}' | while read -r processID; do
echo "Minecraft NOT accepted $currenttime kill process $processID"
kill $processID
sleep 2
count=$(ps -aux | grep minecraft | wc -l)
echo "$(date +%Y%m%d) $(date +%H%M%S) Ausserhalb der Zeit $count" >> zockalarmDay.txt
kill -9 $processID
done
ps -aux | grep Roblox | grep vincent | awk '{print $2}' | while read -r processID; do
echo "Minecraft NOT accepted $currenttime kill process $processID"
kill $processID
sleep 2
count=$(ps -aux | grep minecraft | wc -l)
echo "$(date +%Y%m%d) $(date +%H%M%S) Ausserhalb der Zeit $count" >> zockalarmDay.txt
kill -9 $processID
done
exit
fi
if [[ "$currenttime" > "14:00" ]] || [[ "$currenttime" < "06:30" ]]; then
FIREFOX="firefox"
else
FIREFOX="xxxxxxxxx"
fi
count=$(ps -aux | grep -e minecraft -e $FIREFOX | wc -l)
processID=$(ps -aux | grep -e minecraft -e $FIREFOX | awk '{print $2}')
if [ -e $calendarWeek ]
then
USAGE=name=$(cat "$calendarWeek")
else
USAGE=0
# reset time extension on new week
pushd $BASEDIR
git reset --hard
popd 1>/dev/null
fi
sum=$(( $USAGE + $INTERVAL ))
if (( $count > "1" )); then
echo "found $count means $sum > $calendarWeek"
echo $sum > $calendarWeek
touch $calendarWeek
chmod g-w $calendarWeek
/home/hannes/git/surveillanceCam/scripts/sendNotification.sh -t Minecraft -p "Zockerei process=$processID Spielminuten=$sum" &
echo "$(date +%Y%m%d) $(date +%H%M%S) Zockalarm process=$processID Spielminuten=$sum" >> zockalarm.txt
sleep 3
fi
set -x
if (( $count < "2" )); then
echo "alles gut $count ."
elif (( $sum > $ZUVIEL ))
then
echo "kill process $processID"
kill $processID
sleep 4
count=$(ps -aux | grep minecraft | wc -l)
echo "$(date +%Y%m%d) $(date +%H%M%S) GAME OVER $count" >> zockalarm.txt
wall "Du spielst diese Woche schon sein $sum Minuten. Das war es es jetzt ! GAME OVER" &
kill -9 $processID
/home/hannes/git/surveillanceCam/scripts/sendNotification.sh -t Minecraft -p "Zock Kill process=$processID Spielminuten=$sum" &
elif (( $sum > $ERLAUBT ))
then
echo "$(date +%Y%m%d) $(date +%H%M%S) Hör auf jetzt" >> zockalarm.txt
wall "Du spielst diese Woche schon sein $sum Minuten. Hör auf jetzt !" &
else
echo "nicht zu tun count=$count sum=$sum"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment