Skip to content

Instantly share code, notes, and snippets.

@eddiez9
Created May 17, 2021 23:46
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 eddiez9/7b544a8c7a2cc7de86a62152276db9fd to your computer and use it in GitHub Desktop.
Save eddiez9/7b544a8c7a2cc7de86a62152276db9fd to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script checks for the presence of a process using high GPU memory other than its own etherum miner, and terminates the miner. If it does not find such a process, it starts the miner.
MAX_MEMORY=500
MINER_NAME=t-rex
MINER_PATH="/home/trex/t-rex -a ethash -o stratum+tcp://asia1.ethermine.org:4444 -u WALLET_ADDRESS -w hashcat1"
# Get data on GPU processes
gpuprocs=$(nvidia-smi | head -n -1 | sed -n -e '19,999999 p' | awk 'BEGIN{ OFS = ";"; FS=" *"}{split($0,a);print a[5],a[6],(a[8]+0)}')
for proc in $gpuprocs
do
memory=$(echo $proc | awk -F";" '{print $3}')
pid=$(echo $proc | awk -F";" '{print $1}')
if [ $memory -gt $MAX_MEMORY ] && [ $(ps -p $pid -o comm=) != $MINER_NAME ]; then
echo "Found priority process, killing miner..."
tpids=$(pidof $MINER_NAME)
for tpid in $tpids
do
echo "Killing $tpid."
kill $tpid
done
echo "Done here, exiting"
exit 0
fi
done
pidof $MINER_NAME >/dev/null && echo "Miner is already running" || /usr/sbin/runuser -l trex -c "screen -dmS trex $MINER_PATH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment