Bitcoin Forum
December 07, 2016, 02:45:54 PM *
News: Latest stable version of Bitcoin Core: 0.13.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Bash script sends BTC to central wallet  (Read 2343 times)
racerx
Jr. Member
*
Offline Offline

Activity: 37


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.
1481121954
Hero Member
*
Offline Offline

Posts: 1481121954

View Profile Personal Message (Offline)

Ignore
1481121954
Reply with quote  #2

1481121954
Report to moderator
1481121954
Hero Member
*
Offline Offline

Posts: 1481121954

View Profile Personal Message (Offline)

Ignore
1481121954
Reply with quote  #2

1481121954
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1481121954
Hero Member
*
Offline Offline

Posts: 1481121954

View Profile Personal Message (Offline)

Ignore
1481121954
Reply with quote  #2

1481121954
Report to moderator
racerx
Jr. Member
*
Offline Offline

Activity: 37


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: 1134


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
Jr. Member
*
Offline Offline

Activity: 37


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:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!