Bitcoin Forum
November 11, 2024, 04:59:49 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bash script sends BTC to central wallet  (Read 2669 times)
racerx (OP)
Jr. Member
*
Offline Offline

Activity: 37
Merit: 2


View Profile
October 11, 2010, 02:58:43 PM
 #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.
racerx (OP)
Jr. Member
*
Offline Offline

Activity: 37
Merit: 2


View Profile
October 14, 2010, 03:15:26 PM
 #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.
grondilu
Legendary
*
Offline Offline

Activity: 1288
Merit: 1080


View Profile
October 22, 2010, 11: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

racerx (OP)
Jr. Member
*
Offline Offline

Activity: 37
Merit: 2


View Profile
October 28, 2010, 09:36:02 PM
 #4

Brilliant! thanks, it really needed a bit of a cleanup.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!