Snail/usr/local/sbin/snail.autostop
2011-12-25 02:45:06 +03:00

37 lines
550 B
Bash
Executable File

#!/bin/sh
LOCK_FILE=/tmp/.snail.nvrun.lock
NVRUN=nvrun
while [ 1 ]; do
pgrep "$NVRUN" &>/dev/null
if [ 0 -ne $? ]; then
(
for i in `seq 32`; do
flock -n 9
status=$?
if [[ 0 -ne $status && 5 -eq $i ]]; then
echo "Cann't lock $COUNT_FILE. Exiting..."
exit -1
elif [ 0 -eq $status ]; then
break
fi
sleep 1
done
snail.nvoff
[ 0 -ne $? ] && echo "Error: Cann't switch off nVidia graphics. Exiting..." && exit -1
echo "nVidia chip powered off."
exit 0
) 9>$LOCK_FILE ; exit $?
fi
sleep 1
done