So I finished setting up my Raspberry Pi 3 for a crypto wallet, which need to be 24/7 running for staking (it means that if you have money on the wallet and let it run, sometimes you'll get a reward for that)

But now I want to automatize things for a bit, so here is the situation : I want to create a script running 24/7 and alerting me by email if staking is off, or if the wallet crash, to check that I have a command, getinfo which returns :

{
    "version" : 3000600,
    "protocolversion" : 70912,
    "walletversion" : 61000,
    "balance" : 0.00000000,
    "zerocoinbalance" : 0.00000000,
    "blocks" : 1054716,
    "timeoffset" : 0,
    "connections" : 16,
    "proxy" : "",
    "difficulty" : 194154.74931052,
    "testnet" : false,
    "moneysupply" : 55667642.94565828,
    "zPIVsupply" : {
        "1" : 13973.00000000,
        "5" : 14615.00000000,
        "10" : 63670.00000000,
        "50" : 66800.00000000,
        "100" : 200800.00000000,
        "500" : 193000.00000000,
        "1000" : 350000.00000000,
        "5000" : 380000.00000000,
        "total" : 1282858.00000000
    },
    "keypoololdest" : 1498147446,
    "keypoolsize" : 1001,
    "unlocked_until" : 0,
    "paytxfee" : 0.00000000,
    "relayfee" : 0.00010000,
    "staking status" : "Staking Not Active", # here is the line that interest me
    "errors" : ""
}

and also the command getstakingstatus which returns :

{
    "validtime" : true,
    "haveconnections" : true,
    "walletunlocked" : false,
    "mintablecoins" : false,
    "enoughcoins" : true,
    "mnsync" : true,
    "staking status" : false
}

As you can see, there is a line "staking status", and I want to check if it's returning "true" or "Staking Active" I also want to be able to restart the wallet in case it crashes, so I don't ave to go to my rpi and restart it by hand..

So my bash knowledge is very limited, in school I only had two lessons of Bash and this was my weakest language.. I have some ideas on how to do that, but I'm not quite sure so I planned on doing something like that :

./pivx-cli getinfo > info.txt
cat info.txt | grep -E 'staking status'

and that's basically all I can do :| Though I know that the grep command will only return me "staking status", I don't know how to get the whole line.. I know that for a condition I need to use something like if ... fi ? And for the email I guess I have to set up a mail server, and have a file where every information I want mentioned

Sorry if it's messy but I have really no idea on how to do that, I'm trying my best but I have close to no knowledge in that language !

If you need anything else just tell me and I'll do my best to provide you the information, even though I'd rather learn by myself so maybe a few links could be enough !

Thank you

  • Unless your really set on bash, I would use python because you can easily parse out the text you want. And it doesnt have to be run 24/7 (what if that script crashes???) but set it up as a Cron job to run every minute (or less if you want) – Chad G Feb 28 at 16:29
  • @ChadG Well I'm not really good on bash but this was the first thing to come to my mind when I thought of doing a script ahah.. I don't know anything about Python however :/ Also what I meant when saying "24/7" was that the script would run without me having to launch it, so you're right saying that I should set it up to run every minute ! – Keopha Feb 28 at 17:48
  • Do a little searching on subprocess calls from python and getting the output. If you decide to go that way and run into an issue, update the question with new info and we can figure it out, should be pretty straight forward though – Chad G Feb 28 at 18:02
  • You may want to consider adding your wallet app to autorun and restarting the RPi automatically from time to time. Sending an e-mail from an unknown host has become complicated lately due to anti-spam measures. – Dmitry Grigoryev Feb 28 at 18:55
  • instead of cat info.txt | grep -E 'staking status' you can use grep -E 'staking status' info.txt – Fabian Feb 28 at 23:01

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.