I wrote these bash scripts to call the RPC interface to cgminer.
The machines mainpc, amd1, amd2 are in /etc/hosts assigned to lan IP addresses.
The BFL single is running on a separate instance of cgminer using port 4029.
These scripts are functional, and currently running under ubuntu 11.10
I'm taking advantage of the watch command so this code only executes one pass to gather all the data for all the machines, then watch repeats the process at an arbitrary interval. See invocation script at end of post.
First script for devices (cgm-dev)
#!/bin/bash
LOGNAME=$HOME/logs/cgmdev-$(date +%j).log
touch $LOGNAME
echo -n "»RPC Start: $(date +"%m/%d/%Y %T") »»" | tee -a $LOGNAME
#for GPU in 0 1; do echo "{\"command\":\"gpu\",\"parameter\":\"$GPU\"}" | nc amd1 4028 | sed 's/\x0$//' | python -mjson.tool 2> /dev/null > $HOME/logs/.amd1-$GPU.txt; done
for GPU in 0 1; do echo "{\"command\":\"gpu\",\"parameter\":\"$GPU\"}" | nc amd2 4028 | sed 's/\x0$//' | python -mjson.tool 2> /dev/null > $HOME/logs/.amd2-$GPU.txt; done
for GPU in 0 1 2 3; do echo "{\"command\":\"gpu\",\"parameter\":\"$GPU\"}" | nc mainpc 4028 | sed 's/\x0$//' | python -mjson.tool 2> /dev/null > $HOME/logs/.main-$GPU.txt; done
for PGA in 0 1 2; do echo "{\"command\":\"pga\",\"parameter\":\"$PGA\"}" | nc mainpc 4029 | sed 's/\x0$//' | python -mjson.tool 2> /dev/null > $HOME/logs/.bfl-$PGA.txt; done
echo "End: $(date +"%m/%d/%Y %T")" | tee -a $LOGNAME
function parse_device ()
{
# arg1 is node
# arg2 is gpu/device
# arg3 is logname
GPUTEMP="----"; FANSPEED="--"; MHS="------"; GPUCLOCK="---"; MEMCLOCK="---"; REJECTED="----"; ACCEPTED="------"; UTILITY="-----"; LASTSHARETIME="0"; LASTSHAREPOOL="-"; STATUS="------"
while read cline ; do
#DEBUGGING=$(echo $cline | awk '{ print "1="$1, "2="$2, "3="$3, "4="$4, "5="$5; exit; }' | sed 's/[:,\"]//g' )
#echo $DEBUGGING
FLD1=$(echo $cline | awk '{ print $1; exit; }' | sed 's/[:,\"]//g' )
FLD2=$(echo $cline | awk '{ print $2; exit; }' | sed 's/[:,\"]//g' )
FLD3=$(echo $cline | awk '{ print $3; exit; }' | sed 's/[:,\"]//g' )
if [ "$FLD1" == "Temperature" ] ; then
GPUTEMP=$FLD2
elif [ "$FLD1" == "Fan" ] ; then
if [ "$FLD2" == "Percent" ] ; then
FANSPEED=$(echo $cline | awk '{ printf("%2i", $3); exit; }' )
fi
elif [ "$FLD1" == "MHS" ] ; then
if [ "$FLD2" == "av" ] ; then
MHS=$(echo $cline | awk '{ printf("%6.2f", $3); exit; }' )
fi
elif [ "$FLD1" == "Memory" ] ; then
MEMCLOCK=$FLD3
elif [ "$FLD1" == "GPU" ] ; then
if [ "$FLD2" == "Clock" ] ; then
GPUCLOCK=$FLD3
fi
elif [ "$FLD1" == "Accepted" ] ; then
ACCEPTED=$(echo $cline | awk '{ printf("%7i", $2); exit; }' )
elif [ "$FLD1" == "Rejected" ] ; then
REJECTED=$(echo $cline | awk '{ printf("%4i", $2); exit; }' )
elif [ "$FLD1" == "Utility" ] ; then
UTILITY=$(echo $cline | awk '{ printf("%5.2f", $2); exit; }' )
elif [ "$FLD3" == "Time" ] ; then
LASTSHARETIME=$(date --date=@$(echo $cline | awk '{ print $4; exit; }' | sed 's/[:,\"]//g' ) +"%d%b %T")
elif [ "$FLD3" == "Pool" ] ; then
LASTSHAREPOOL=$(echo $cline | awk '{ printf("%3i", $4); exit; }' | sed 's/[:,\"]//g' )
elif [ "$FLD1" == "Status" ] ; then
STATUS=$FLD2
if [ "$STATUS" != "Alive" ] ; then
yad --image "dialog-warning" --title "Warning" --button=gtk-ok --text "$NODE dev$GPU reports $STATUS" &
fi
fi
done < $HOME/logs/.$1-$2.txt
NODE=$(echo $1 | awk '{ printf("%-4s", $1); exit; }' )
echo "$NODE dev$2 $GPUTEMP $FANSPEED $MHS $GPUCLOCK $MEMCLOCK $REJECTED $ACCEPTED $UTILITY $LASTSHARETIME $LASTSHAREPOOL $STATUS" | tee -a $3
}
echo "Node GPU Temp F% MH/S GPU Mem Rej Accept Util Last share Pool Status" | tee -a $LOGNAME
echo "---- ---- ---- -- ------ --- --- ---- ------ ---- -------------- ---- ------" | tee -a $LOGNAME
#for NODE in "amd1" "amd2" ; do
NODE="amd2"
for GPU in 0 1; do
parse_device $NODE $GPU $LOGNAME
done
#done
for GPU in 0 1 2 3; do
parse_device main $GPU $LOGNAME
done
for PGA in 0 1 2; do
parse_device bfl $PGA $LOGNAME
done
echo "^$(date +"%m/%d/%Y %T")^" | tee -a $LOGNAME
Script for summary data.
#!/bin/bash
# RPC the summary data
DOY=$(date +%j)
LOGNAME=$HOME/logs/cgmsumm-$DOY.log
touch $LOGNAME
echo -n "»RPC Start: $(date +"%m/%d/%Y %T")»»" | tee -a $LOGNAME
echo "{\"command\":\"summary\"}" | nc amd1 4028 | sed 's/\x0$//' | python -mjson.tool 2> /dev/null > $HOME/logs/.amd1-sum.txt
echo "{\"command\":\"summary\"}" | nc amd2 4028 | sed 's/\x0$//' | python -mjson.tool 2> /dev/null > $HOME/logs/.amd2-sum.txt
echo "{\"command\":\"summary\"}" | nc mainpc 4028 | sed 's/\x0$//' | python -mjson.tool 2> /dev/null > $HOME/logs/.main-sum.txt
echo "{\"command\":\"summary\"}" | nc mainpc 4029 | sed 's/\x0$//' | python -mjson.tool 2> /dev/null > $HOME/logs/.bfls-sum.txt
echo "End: $(date +"%m/%d/%Y %T")" | tee -a $LOGNAME
echo "Node Reject Accepted Util MHS Getworks RemFail Local Discard Found HW Err Network Uptime" | tee -a $LOGNAME
echo "---- ------ -------- ---- ------- -------- ------- ----- ------- ----- ------ ------- ---------" | tee -a $LOGNAME
for NODE in "amd1" "amd2" "main" "bfls"; do
while read cline ; do
#DEBUGGING=$(echo $cline | awk '{ print "1="$1, "2="$2, "3="$3; exit; }' | sed 's/[:,\"]//g' )
#echo "$NODE: $DEBUGGING"
FLD1=$(echo $cline | awk '{ print $1; exit; }' | sed 's/[:,\"]//g' )
#
if [ "$FLD1" == "Getworks" ] ; then
SUMMGW=$(echo $cline | awk '{ printf("%8i", $2); exit; }' | sed 's/[:,\"]//g')
elif [ "$FLD1" == "Accepted" ] ; then
SUMMAC=$(echo $cline | awk '{ printf("%8i", $2); exit; }' | sed 's/[:,\"]//g')
elif [ "$FLD1" == "Rejected" ] ; then
SUMMRJ=$(echo $cline | awk '{ printf("%5i", $2); exit; }' | sed 's/[:,\"]//g')
elif [ "$FLD1" == "Remote" ] ; then
SUMMRF=$(echo $cline | awk '{ printf("%6i", $3); exit; }' | sed 's/[:,\"]//g' )
elif [ "$FLD1" == "Utility" ] ; then
SUMMUT=$(echo $cline | awk '{ printf("%7.2f", $2); exit; }' | sed 's/[:,\"]//g' )
elif [ "$FLD1" == "MHS" ] ; then
SUMMHS=$(echo $cline | awk '{ printf("%7.2f", $3); exit; }' | sed 's/[:,\"]//g' )
elif [ "$FLD1" == "Local" ] ; then
SUMMLW=$(echo $cline | awk '{ printf("%6i", $3); exit; }' | sed 's/[:,\"]//g' )
elif [ "$FLD1" == "Discarded" ] ; then
SUMMDW=$(echo $cline | awk '{ printf("%7i", $2); exit; }' | sed 's/[:,\"]//g' )
elif [ "$FLD1" == "Found" ] ; then
SUMMFB=$(echo $cline | awk '{ printf("%5i", $3); exit; }' | sed 's/[:,\"]//g' )
elif [ "$FLD1" == "Hardware" ] ; then
SUMMHW=$(echo $cline | awk '{ printf("%6i", $3); exit; }' | sed 's/[:,\"]//g' )
elif [ "$FLD1" == "Network" ] ; then
SUMMNB=$(echo $cline | awk '{ printf("%7i", $3); exit; }' | sed 's/[:,\"]//g' )
elif [ "$FLD1" == "Elapsed" ] ; then
SUMMET=$(echo $cline | awk '{ printf("%9i", $2); exit; }' | sed 's/[:,\"]//g' )
fi
done < $HOME/logs/.$NODE-sum.txt
echo "$NODE $SUMMRJ $SUMMAC $SUMMUT $SUMMHS $SUMMGW $SUMMRF $SUMMLW $SUMMDW $SUMMFB $SUMMHW $SUMMNB $SUMMET" | tee -a $LOGNAME
SUMMGW=""; SUMMAC=""; SUMMRJ=""; SUMMRF=""; SUMMUT=""; SUMMHS=""; SUMMLW=""; SUMMDW=""; SUMMFB=""; SUMMHW=""; SUMMNB=""; SUMMET="";
done
echo "^$(date +"%m/%d/%Y %T")^" | tee -a $LOGNAME
Also pool data:
#!/bin/bash
# RPC the pool data
DOY=$(date +%j)
LOGNAME=$HOME/logs/cgmpools-$DOY.log
touch $LOGNAME
echo -n "»RPC Start: $(date +"%m/%d/%Y %T")»»" | tee -a $LOGNAME
echo "{\"command\":\"pools\"}" | nc mainpc 4028 | sed 's/\x0$//' | python -mjson.tool > $HOME/logs/.main-pools.txt
echo "{\"command\":\"pools\"}" | nc mainpc 4029 | sed 's/\x0$//' | python -mjson.tool > $HOME/logs/.bfl0-pools.txt
echo "{\"command\":\"pools\"}" | nc amd1 4028 | sed 's/\x0$//' | python -mjson.tool > $HOME/logs/.amd1-pools.txt
echo "{\"command\":\"pools\"}" | nc amd2 4028 | sed 's/\x0$//' | python -mjson.tool > $HOME/logs/.amd2-pools.txt
echo "End: $(date +"%m/%d/%Y %T")" | tee -a $LOGNAME
echo "Node Pool Status Pr LP Rej Accepted Getworks URL " | tee -a $LOGNAME
echo "---- ---- -------- -- -- ----- -------- -------- -----------------" | tee -a $LOGNAME
for node in "amd1" "amd2" "main" "bfl0"; do
while read cline ; do
#DEBUGGING=$(echo $cline | awk '{ print "1="$1, "2="$2, "3="$3; exit; }' | sed 's/[:,\"]//g' )
#echo "$node: $DEBUGGING"
FLD1=$(echo $cline | awk '{ print $1; exit; }' | sed 's/[:,\"]//g')
if [ "$FLD1" == "POOL" ] ; then
POOLNUM=$(echo $cline | awk '{ print $2; exit; }' | sed 's/[,\"]//g')
elif [ "$FLD1" == "Priority" ] ; then
POOLPRI=$(echo $cline | awk '{ print $2; exit; }' | sed 's/[,\"]//g')
elif [ "$FLD1" == "Accepted" ] ; then
POOLACC=$(echo $cline | awk '{ printf("%8i", $2); exit; }' | sed 's/[,\"]//g')
elif [ "$FLD1" == "Rejected" ] ; then
POOLREJ=$(echo $cline | awk '{ printf("%5i", $2); }' | sed 's/[,\"]//g')
elif [ "$FLD1" == "Getworks" ] ; then
POOLGW=$(echo $cline | awk '{ printf("%8i", $2); exit; }' | sed 's/[,\"]//g')
elif [ "$FLD1" == "Status" ] ; then
POOLSTS=$(echo $cline | awk '{ printf("%13s", $2); exit; }' | sed 's/[,\"]//g')
elif [ "$FLD1" == "Long" ] ; then
POOLLP=$(echo $cline | awk '{ print $3; exit; }' | sed 's/[,\"]//g')
elif [ "$FLD1" == "URL" ] ; then
POOLURL=$(echo $cline | awk '{ print $2; exit; }' | sed 's/[,\"]//g')
if [ $POOLACC -gt 0 ] ; then
echo "$NODE $POOLNUM $POOLSTS $POOLPRI $POOLLP $POOLREJ $POOLACC $POOLGW $POOLURL " | tee -a $LOGNAME
fi
POOLNUM=""; POOLSTS=""; POOLPRI=""; POOLLP=""; POOLACC=""; POOLREJ=""; POOLGW=""; POOLURL="";
fi
done < $HOME/logs/.$node-pools.txt
done
echo "^$(date +"%m/%d/%Y %T")^" | tee -a $LOGNAME
Invocation script
#!/bin/bash
cd $HOME
CGDEV="watch -n 77 nice ./cgm-dev"
exec gnome-terminal --command="$CGDEV" --title="Devices" --geometry=80x15-0+0 &
CGPOOLS="watch -n 91 nice ./cgm-pools"
exec gnome-terminal --command="$CGPOOLS" --title="Pools" --geometry=82x22-0+0 &
CGSUMM="watch -n 57 nice ./cgm-summ"
exec gnome-terminal --command="$CGSUMM" --title="Summary" --geometry=102x10-0+0 &
Example script for switching all pools via RPC [I know it's very weak error handling]
#!/bin/bash
# switch all pools using RPC with pauses
function countdown() {
secs=$1
while [ $secs -gt 0 ] ; do
sleep 1 &
echo -n .
secs=$(($secs - 1))
wait
done
echo
}
if [ $# -eq 1 ] ; then
echo "switchpool|$1" | nc mainpc 4028 | sed 's/|\x0$//g' | awk 'BEGIN { FS=","; } ; { for (i=1;i<=NF;i++) { print $i } exit; }'
countdown 3
echo "switchpool|$1" | nc mainpc 4029 | sed 's/|\x0$//g' | awk 'BEGIN { FS=","; } ; { for (i=1;i<=NF;i++) { print $i } exit; }'
countdown 3
#echo "switchpool|$1" | nc amd1 4028 | sed 's/|\x0$//g' | awk 'BEGIN { FS=","; } ; { for (i=1;i<=NF;i++) { print $i } exit; }'
#countdown 3
echo "switchpool|$1" | nc amd2 4028 | sed 's/|\x0$//g' | awk 'BEGIN { FS=","; } ; { for (i=1;i<=NF;i++) { print $i } exit; }'
echo ""
else
echo "Switch cgminer pool"
echo " arg1 0-n assuming the same on each machine"
fi
Script for quitting all instance of cgminer.
#!/bin/bash
if [ $# -eq 1 ] ; then
if [ $1 == "--all" ] ; then
echo -n "stop mainpc-gpu.."
echo "{\"command\":\"quit\"}" | nc mainpc 4028 | sed 's/\x0$//'
echo "stop mainpc-gpu sent "
sleep 2
echo -n "stop mainpc-bfl.."
echo "{\"command\":\"quit\"}" | nc mainpc 4029 | sed 's/\x0$//'
echo "stop mainpc-bfl sent "
sleep 2
echo -n "stop amd1.."
echo "{\"command\":\"quit\"}" | nc amd1 4028 | sed 's/\x0$//'
echo "stop amd1 sent "
sleep 2
echo -n "stop amd2.."
echo "{\"command\":\"quit\"}" | nc amd2 4028 | sed 's/\x0$//'
echo "stop amd2 sent "
echo ..done
fi
fi