# Adjust this variable to the name of your xcash-daemon unit file name
XCASH_DAEMON_SRV=xcash-daemon
# Adjust this variable to the name of your xcash-wallets unit file name
XCASH_WALLET_SRV=xcash-rpc-wallet
# Adjust this variable to the name of your xcash-dpops unit file name
XCASH_DPOPS_SRV=xcash-dpops
# Adjust this variable to the name of your mongodb unit file name
DAEMON_URL="http://127.0.0.1:18281/json_rpc"
WALLET_URL="http://127.0.0.1:18285/json_rpc"
CURL='curl -w "\n" -s -H "Content-Type: application/json" -X'
if lsof -Pi :18281 -sTCP:LISTEN -t >/dev/null ; then
DATA=`$CURL GET $DAEMON_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_block_count"}'`
HEIGHT=$(echo "$DATA" | grep '"count"' | awk {'print $2'} | sed s'|,||g' | tr -d #x27;\r')
STATUS=$(echo "$DATA" | grep '"status"' | awk {'print $2'} | sed s'|"||g' | tr -d #x27;\r')
if [ $STATUS == "OK" ]; then
STATUS=${green}OK${reset}
SATTUS=${red}FAIL${reset}
echo -e "Blockhain sync status: $STATUS"
echo "Blockchain height: $HEIGHT"
echo "X-Cash Daemon service is not running...."
echo "Check the $XCASH_DAEMON_SRV service status"
function get_node_balance(){
if lsof -Pi :18285 -sTCP:LISTEN -t >/dev/null ; then
DATA=`$CURL GET $WALLET_URL -d '{"jsonrpc":"2.0","id":"0","method":"get_balance","params":{"account_index":0,"address_indices":[0]}}'`
ADDR=$(echo "$DATA" | grep '"address"' | awk {'print $2'} | sed s'|"||g' | sed s'|,||g' | head -1 | tr -d #x27;\r')
UNSPENT_OUTPUTS=$(echo "$DATA" | grep '"num_unspent_outputs"' | awk {'print $2'} | sed s'|"||g' | sed s'|,||g' | head -1 | tr -d #x27;\r')
ATOMIC_TOTAL_BALANCE=$(echo "$DATA" | grep '"balance"' | awk {'print $2'} | sed s'|,||g' | head -1 | tr -d #x27;\r')
ATOMIC_UNLOCKED_BALANCE=$(echo "$DATA" | grep '"unlocked_balance"' | awk {'print $2'} | sed s'|,||g' | head -1 | sed s"|^M||g" | tr -d #x27;\r')
TOTAL_BALANCE=$((ATOMIC_TOTAL_BALANCE/1000000))
UNLOCKED_BALANCE=$((ATOMIC_UNLOCKED_BALANCE/1000000))
echo "Public address: $ADDR"
echo "Unspent outputs: $UNSPENT_OUTPUTS"
echo "Total balance: $TOTAL_BALANCE XCASH"
echo "Unlocked balance: $UNLOCKED_BALANCE XCASH"
echo "X-Cash RCP Wallet service is not running...."
echo "Check the $XCASH_WALLET_SRV service status"
function check_services_status(){
MONGODB_UP_SINCE=$(systemctl show $MONGODB_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
XCASH_DAEMON_UP_SINCE=$(systemctl show $XCASH_DAEMON_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
XCASH_WALLET_UP_SINCE=$(systemctl show $XCASH_WALLET_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
XCASH_DPOPS_UP_SINCE=$(systemctl show $XCASH_DPOPS_SRV --property=ActiveEnterTimestamp | sed s"|ActiveEnterTimestamp=||g")
systemctl is-active $MONGODB_SRV --quiet \
&& echo -e ${green}MongoDB service is running since...............$MONGODB_UP_SINCE${reset} \
|| echo -e ${red}MongoDB service is not running${reset}
systemctl is-active $XCASH_DAEMON_SRV --quiet \
&& echo -e ${green}X-Cash Daemon service is running since.........$XCASH_DAEMON_UP_SINCE${reset} \
|| echo -e ${red}X-Cash Daemon service is not running${reset}
systemctl is-active $XCASH_WALLET_SRV --quiet \
&& echo -e ${green}X-Cash RPC Wallet service is running since.....$XCASH_WALLET_UP_SINCE${reset} \
|| echo -e ${red}X-Cash RPC Wallet service is not running${reset}
systemctl is-active $XCASH_DPOPS_SRV --quiet \
&& echo -e ${green}X-Cash DPoPS service is running since..........$XCASH_DPOPS_UP_SINCE${reset} \
|| echo -e ${red}X-Cash DPoPS service is not running${reset}