Author

Topic: [TUT] Script - Get an e-mail when a block is found + updown checker (XPM) (Read 883 times)

member
Activity: 113
Merit: 10
Who would one do this in windows? It would save me so much time Smiley
donator
Activity: 112
Merit: 10
keybase.io/arblarg
Ok well, as many others I am mining from different machines, and well, checking all of them for found blocks is very hard, also I am not using the same wallet for all of them so basically I prefer the machines to e-mail me when they find a block.

Also the script checks if primecoind is still running, and if it's not it tries to start it again.

1. Install a mail server (if you don't have one) so that you can receive e-mails

On Debian/Ubuntu you should install exim4 in order to get your e-mail working.
Code:
apt-get update
apt-get upgrade
apt-get install exim4-daemon-light mailutils
dpkg-reconfigure exim4-config

On CentOS/Slackware/Arch/Gentoo I am sure you will find many tutorials of doing this.

2. Save this script in a file and make it executable (chmod +x filename)

Code:
#!/bin/bash

primecoind=`which primecoind`

#we check if primecoind is running and if not we start it again
if ! pgrep -f $primecoind >/dev/null 2>&1; then
$primecoind --daemon
sleep 10
fi

#we check if a block was found or not
generated=`cat $HOME/.primecoin/debug.log | grep generated | grep -v prime | sed 's/generated //g'`

if [ -z "$generated" ] ; then
exit
fi

#we found a block
ip=`hostname -I`
$primecoind listtransactions | /usr/bin/mail -s "I found one! $generated XPM $ip" -r primecoind@$ip  [email protected]

#clean up and server restart
$primecoind stop
sleep 10
rm -rf $HOME/.primecoin/debug.log
$primecoind --daemon

3. Add this to your cron daemon

Code:
crontab -e

And add the following:

For 15 minutes checks:

Code:
0,15,30,45 * * * * /path/to/yourscript

For hourly checks:

Code:
0 */2 * * *  /path/to/yourscript

Save and close.

To check that it was added:

Code:
crontab -l

Regards

P.S. This script can be easily modified to work with any daemon by fiddling with 'which primecoind' maybe replacing it with 'which bitcoind', not just the primecoin one, because I think they all work the same way.
Jump to: