Can you get a bash script to run multiple geth commands and wait for callbacks?

The Problem

I want to be able to do some tasks repeatedly - they involve creating a contract and, once it is created, transfer some ether into it from a previous contract and various other things.
But it requires the contract to be mined, so that you get its address, and use that address for the subsequent operations.

You can daisy chain that from the geth console by nesting subsequent operations in the callback of the previous operation. You can see what I mean here: (at the bottom)

But then we wanted to put this on a cron to run every week so we created a bash script that did

geth --exec loadScript("weekly_deploy.js") attach

..but the problem is that it executes the first bit, i.e. send the contract to the blockchain (where it gets mined and everything), but it does not wait for the callback, so the rest of the execution does not happen.

Is there any way of creating a script that can be executed in such a way that it will wait for the "contract mined" callback and carry on executing?

Hope this makes sense!

Many thanks


  • desktopdandesktopdan Member Posts: 15
    So I have found the answer to my own question.... I am posting it here in case anyone else is interested.

    I used expect

    You can install it with sudo apt-get install expect

    And then you can write a simple script that attaches to the geth console, runs your commands and exits. Here is a simple expect script that prints out the account addresses:
    spawn /usr/bin/geth attach
    expect ">"
    send "eth.accounts\r"
    expect ">"
    set results $expect_out(buffer)
    send "exit\r"
    expect eof
Sign In or Register to comment.