Bitcoin Forum
May 05, 2024, 09:37:13 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bash script to sound when coins received - need debug  (Read 1087 times)
jago25_98 (OP)
Hero Member
*****
Offline Offline

Activity: 900
Merit: 1000


Crypto Geek


View Profile WWW
August 01, 2013, 09:28:23 PM
 #1

Goal: Make a sound when balance at an address reaches a set number of confirmations

So far:

Code:
#needs:
# - pulseaudio - for paplay
# - curl
# - blockexplorer not 404

address=$1
confirmations="6"
balance=$(curl --fail "http://blockexplorer.com/q/getreceivedbyaddress/$address/$confirmations") || { echo "Unable to retrieve balance" >&2; exit 1; }



while $BALANCE=0
do
 sleep 1s
 echo $BALANCE
done


echo $BALANCE at $ADDRESS received with $CONFIRMATIONS confirmations.
paplay /usr/share/sounds/startup3.wav

Needs a bit of tweaking.

I did a search and found bash scripts in this dev section so I'm posting here... but it doesn't seem the best section to post in, sorry if it's wrong

Bitcoiner since the early days. Crypto YouTube Channel: Trading Nomads | Analyst | News Reporter | Bitcoin Hodler | Support Freedom of Speech!
1714901833
Hero Member
*
Offline Offline

Posts: 1714901833

View Profile Personal Message (Offline)

Ignore
1714901833
Reply with quote  #2

1714901833
Report to moderator
1714901833
Hero Member
*
Offline Offline

Posts: 1714901833

View Profile Personal Message (Offline)

Ignore
1714901833
Reply with quote  #2

1714901833
Report to moderator
1714901833
Hero Member
*
Offline Offline

Posts: 1714901833

View Profile Personal Message (Offline)

Ignore
1714901833
Reply with quote  #2

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

Posts: 1714901833

View Profile Personal Message (Offline)

Ignore
1714901833
Reply with quote  #2

1714901833
Report to moderator
kostagr33k
Full Member
***
Offline Offline

Activity: 309
Merit: 100


View Profile
August 02, 2013, 03:08:51 AM
 #2

Made some changes. Please note I haven't tested thoroughly and I didnt have time to test on a linux box, so could not install pulseaudio


Code:
#!/bin/sh
#needs:
# - pulseaudio - for paplay
# - curl
# - blockexplorer not 404

address=$1
confirmations="6"
balance=$(curl --fail "http://blockexplorer.com/q/getreceivedbyaddress/$address/$confirmations") || { echo "Unable to retrieve balance" >&2; exit 1; }


while [ `echo ${balance} == 0| bc` -eq 1 ]
do
 sleep 1s
 echo ${balance}
done


echo ${balance} at ${address} received with ${confirmations} confirmations.
paplay /usr/share/sounds/startup3.wav
dudeami
Full Member
***
Offline Offline

Activity: 126
Merit: 100



View Profile
August 02, 2013, 09:46:57 PM
 #3

Good job, I like the ingenuity! I see two issues with your script:

1) It only checks if the amount is over 0. You should save the balance at startup (such as initbalance) so users that already have balances can use it.

2) Your abusing the free API access pretty badly, and you might unknowingly run into your 8 hour limit within 3 hours.

From the bottom of https://blockchain.info/api

Requests in 8 Hours: (Maximum : 10000)
Requests in 5 minutes: (Maximum : 500)

Your making 28800 (if curl responds instantly) api calls in a 8 hour period. I would suggest polling every 3 seconds to barely make it in the limits (9600 requests a day) or 10+ seconds to be nice to blockchain.info for their free api service. I personally don't need to know that second that I received some coins.

Other than that, keep up the great work!

Put your heart on the line, it determines your fate.
BTC: 1DUDEAMiV54PFJFSe5fen3wr1e71unkaGj
kostagr33k
Full Member
***
Offline Offline

Activity: 309
Merit: 100


View Profile
August 03, 2013, 02:21:20 AM
 #4

I kept the script as is, as I havn't scripted against blockchain.info, but Yes, the timing should be changed to make things nicer for them ;p


kosta
dudeami
Full Member
***
Offline Offline

Activity: 126
Merit: 100



View Profile
August 03, 2013, 03:30:51 AM
 #5

I kept the script as is, as I havn't scripted against blockchain.info, but Yes, the timing should be changed to make things nicer for them ;p


kosta

All that needs to be changed is

Code:
sleep 1s

to some other value, say 30 seconds:

Code:
sleep 30s

Put your heart on the line, it determines your fate.
BTC: 1DUDEAMiV54PFJFSe5fen3wr1e71unkaGj
kostagr33k
Full Member
***
Offline Offline

Activity: 309
Merit: 100


View Profile
August 03, 2013, 03:51:56 AM
 #6

lol ;p

When I meant I haven't scripted against blockchain.info meant just that. i.e. I don't know there policies so just modified his script as is to hopefully point him in the right direction.

willing to help him further if he does have any questions though ;p


im curious if thats what he was looking for, as i only use linux for servers and not desktops and can't easily test the whole sound thing .

Kosta
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!