Skip to content

Instantly share code, notes, and snippets.

@jmtsantos
Created May 22, 2021 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmtsantos/a1569ff1b1938dd7c201be0d9dd99820 to your computer and use it in GitHub Desktop.
Save jmtsantos/a1569ff1b1938dd7c201be0d9dd99820 to your computer and use it in GitHub Desktop.
script to start your miner or whatever while the screen is locked
#!/bin/bash
# lockscreen-mining.sh script to start your miner or whatever while the screen is locked
XMRIG_BINARY=xmrig
XMRIG_CONFIG=/home/jsantos/opt/xmrig.json
start_miner () {
if pgrep -x $XMRIG_BINARY > /dev/null
then
echo "xmrig already running"
return
else
echo "xmrig not running .. starting"
fi
2>/dev/null 1>&2 $XMRIG_BINARY -B -c $XMRIG_CONFIG &
}
stop_miner () {
pkill -x $XMRIG_BINARY
}
is_screen_locked()
{
if dbus-send --session --dest=org.freedesktop.ScreenSaver --type=method_call --print-reply /org/freedesktop/ScreenSaver org.freedesktop.ScreenSaver.GetActive | grep 'boolean true' > /dev/null; then
# "locked"
return 0
else
# "unlocked"
return 1
fi
}
# send self to the background
if [[ "$1" != "-n" ]]; then
$0 -n & disown
exit $?
fi
while true; do
if is_screen_locked; then
start_miner
else
stop_miner
fi
sleep 2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment