dotfiles/.local/bin/auto-poweroff.sh
2022-08-20 20:23:03 +02:00

31 lines
445 B
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash -x
# 1: Temps en minutes
# 2: Type dextinction
touch /dev/shm/mccount
while true
do
mcpid="$(pgrep -nu minecraft java)"
mcstatus="$(ps -q "${mcpid}" -o state --no-headers 2>/dev/null)"
if [[ "$mcstatus" == "T" ]]
then
echo . >> /dev/shm/mccount
else
> /dev/shm/mccount
fi
time=$(wc -l /dev/shm/mccount | cut -d" " -f1)
if [[ "$time" -ge "${1:-5}" ]]
then
> /dev/shm/mccount
systemctl "${2:-suspend}"
fi
sleep 60
done