Alert of wallet Payout

I made an extremely simply Bash script that watches the Chia/Folk log files for a key word and sends a push notification if found with the amount that was paid to the wallet.

Wanted to see if anyone would potentially have a more elegant way about doing something like this? Maybe that would have more features and would run in the background smoother than this?

#!/bin/bash


source ${1}

function push {
                curl -s -F "token=$token" \
                -F "user=$user" \
                -F "title=$title" \
                -F "message=$1" https://api.pushover.net/1/messages.json
                }


tail -Fn0 -q $log | \
while read line ; do
        echo "$line" | grep "Adding coin"
        if [ $? = 0 ]
        then
                cutline=${line: -13}
                cutline=${cutline:0:12}
                cutline=echo '${cutline} / 100000000000' | bc -l
                alert="You just Received ${cutline}!"
                push "$alert"
        fi
done

source ${1} is a config file with push info and location of log file.

People mention chiadog quite a lot

I love ChiaDog, But when you have one alert setup it sends ALL alerts to it. Throughout the day there’s always 1-2 maybe more signages missed. Along with other issues. By the end of the day you end up with 10-15 alerts a day. Completely necessary. But wanted something that just alerts me on payouts.

I use Chiadog, and I have its alerts just send to discord so I can check in on it from time to time.

I came up with a different way of doing, not necessarily better though. This chunk of code is from a larger bash script I created that does logging and inserts data into a database for a dashboard web app that I made.

But the script basically captures the results of the command “chia wallet show” and then parses it and gets the balance. It checks the value against the value in the history file and if different then does a few things: write the history file, send email, insert into db, and run another Bash script to store transaction data.

Not that anyone would do it this way, but I always find it interesting to read through other peoples code, so I thought I’d share.

#!/bin/bash

cd ~/chia-blockchain
. ./activate

# get wallet balance and check to see if it's different from the last balance. Email if so, also update the db.
bal=`chia wallet show | grep '   .Total Balance:' | cut --fields 6 --delimiter=\ | head -n 1`
echo "bal = $bal" >>~/sourcecode/monchia/.monchia.log
lastbal=`cat ~/sourcecode/monchia/.walletbalance`
if [ "$bal" != "$lastbal" ]; then
        echo $bal >~/sourcecode/monchia/.walletbalance
        printf "Subject: New Chia Confirmed Balance: $bal\n\nConfirmed Balance: $bal" | /usr/sbin/ssmtp steppsr@gmail.com
        curl -s http://192.168.1.133/monchia/api/setwallet/wallet/$bal >>~/sourcecode/monchia/.monchia.log
        sh ~/sourcecode/monchia/newtrx.sh
fi

deactivate

I like this idea and I would actually use it. My issue is that all my chia farms run inside dockers. I would need to run this inside each container. I like the idea though.

I could do something similar by querying a wallet balance. But that would be a lot of queries and the payout wallet changes from time to time.

Wait, I can run “wallet show” from outside the container… You have me thinking now! I like it! Its much cleaner than what I have. I would just need to look chia and all its forks.

I also cheat and instead of using an alerting system, I can send email to my cell number and it converts it to text for me automatically. Only works for me, but I wrote it just for me anyway. :slight_smile:

Hopefully you don’t mind, but I modified it to fit my needs and it works much better than my original. Ill set it up as a cron job.

I may add a few changes as time goes on. Because of how the main Chia container is named I needed to get the chia balance seperatly.

#!/bin/bash

forks="BTCGreen  Cactus  Chives CryptoDoge Flax Flora HDDCoin Maize NChain StaiCoin STOR"
token=
user=

function push {
                curl -s -F "token=$token" \
                -F "user=$user" \
                -F "title=$title" \
                -F "message=$1" https://api.pushover.net/1/messages.json
                }

bal=`docker exec -it machinaris chia wallet show | grep '   .Total Balance:' | cut --fields 6 --delimiter=\ | head -n 1`
echo "Chia - $bal"

lastbal=`cat ~/.walletbalance.chia`

if [ "$bal" != "$lastbal" ]; then
        echo $bal >~/.walletbalance.chia
        title="Chia balance change!"
        alert="You just received $bal"
                push "$alert" >> /dev/null
fi


for fork in ${forks[@]}

do

lowerfork=`echo $fork | tr '[:upper:]' '[:lower:]'`

bal=`docker exec -it machinaris-${lowerfork[@]} ${lowerfork[@]} wallet show | grep '   .Total Balance:' | cut --fields 6 --delimiter=\ | head -n 1`
echo "$fork - $bal"

lastbal=`cat ~/.walletbalance.${lowerfork[@]}`

if [ "$bal" != "$lastbal" ]; then
        echo $bal >~/.walletbalance.${lowerfork[@]}
        title="${fork[@]} balance change!"
        alert="You just received $bal"
                push "$alert" >> /dev/null
fi

done

Not at all. I’m also farming HDDcoin… I probably should look at some of those others as well.

Would you mind sharing it :sweat_smile: , it would be so helpful.

Did you mean the original script or HDDcoin or what?