Author

Topic: Bash script sends BTC to central wallet (Read 2649 times)

jr. member
Activity: 37
Merit: 2
October 28, 2010, 05:36:02 PM
#4
Brilliant! thanks, it really needed a bit of a cleanup.
legendary
Activity: 1288
Merit: 1076
October 22, 2010, 07:42:12 PM
#3
Only issue I had was the cron running as root but I was running bitcoind as a local user... root had no ~/.bitcoind/bitcoin.conf so it was bitching.

I love bash scripting, so please let me help to try to improve this script a bit.

Code:
#!/bin/bash

# put btc address in a variable, for clarity
# and in case we should use it for something else
btc_address=1AVgSRgQ4dF8Fwi3hfvFZ1uhnWoWGT25sR

# store current balance
# and check that bitcoind is running in the same time
if balance=$(bitcoind getbalance)
then
    # always use '[[' instead of '['
    # make sure it works with any number of decimals
    # use quotes
    if [[ "$balance" =~ ^0.0*$ ]]
    then echo "no coins generated"
    else bitcoind sendtoaddress $btc_address $balance
    fi
else
    error=$?
    echo "something went wrong.  Is bitcoind running ?"
    return $error
fi
jr. member
Activity: 37
Merit: 2
October 14, 2010, 11:15:26 AM
#2
Yeah, I saw that but I had issues trying to get it running as it wanted jsonpc stuff. I wanted to get it deployed over quite a few nodes and didnt want alot of manual bits and pieces to addon, perhaps I just missed something obvious Smiley

anyway heres a refined version:

Code:
42 * * * * root if [ $(/usr/local/bin/bitcoind getbalance) = 0.00000000 ]; then echo "No Coins Generated"; else /usr/local/bin/bitcoind sendtoaddress 1AVgSRgQ4dF8Fwi3hfvFZ1uhnWoWGT25sR $(/usr/local/bin/bitcoind getbalance) $HOSTNAME $HOSTNAME; fi

just make a  file and put this in /etc/cron.d

Only issue I had was the cron running as root but I was running bitcoind as a local user... root had no ~/.bitcoind/bitcoin.conf so it was bitching.
jr. member
Activity: 37
Merit: 2
October 11, 2010, 10:58:43 AM
#1
I just got bitcoin up and running on about 50 cores (not servers) across our hosted env and office. All the logging in and checking balances was getting tedious so I wrote a quick and dirty bash script that sits in /etc/cron.daily and sends payments to my central wallet.. I know I could have used json but sometimes a simple bash script is just the way to go Smiley

It assumes that bitcoind is in the PATH.

Code:
#!/bin/bash
balance="$(bitcoind getbalance)"
if [ $balance = 0.00000000 ]
then
      echo "No Coins Generated"
  else
        bitcoind sendtoaddress  1AVgSRgQ4dF8Fwi3hfvFZ1uhnWoWGT25sR $balance $HOSTNAME $HOSTNAME
    fi

Hope someone finds it handy... and feel free to add to it.
Jump to: