Daily monitor Grin nodes/wallets status by email

With help of ChatGPT, I finalized the bash script to monitor all the grin nodes I’m running around the world.
The script will scan ports with specific IPs, then send the result to specific email in every 12 hours by crontab
-Requirements:

  • Grin node is running, the port 3414 is open/allowed from other machines
  • Sending email by postfix, I use ISPConfig to configure Email routing/Relay pointing to use another trusted smtp to send email.
  • Input files: server-list.txt contains IP addresss in each line and port-list.txt contains ports. Those files are in same directory.

Script:

#!/bin/sh

output="/root/multiple_port_scan_result.log"
recipient="support@grinbux.com"
sender_name="Grin Archive Node Chicago"
sender_email="support@grinbux.com"
# Get current date and time in UTC
current_datetime=$(date -u +"%Y-%m-%d %H:%M:%S UTC")

# Create a custom subject with the current date and time
subject="Grin nodes results $current_datetime"
# Clear the output file or create a new one
> "$output"
for server in $(cat server-list.txt);
do
        for port in $(cat port-list.txt);
        do
                #echo $server
                nc -zvw3 "$server" "$port" 2>&1 | tee -a "$output"
                echo "" >> "$output"
done
done
# Read the content of the output file into the email body
email_body=$(cat "$output")

# Send the email using the mail command with sender's name, email, subject, and body
(
echo "Subject: $subject"
echo "To: $recipient"
echo "From: $sender_name <$sender_email>"
echo
echo "$email_body"
) | /usr/sbin/sendmail -t -oi


Crontab:

0 */12 * * * /bin/sh /root/multiple_port_scan.sh

Result:

For the moment, I’m searching around if possible to check multiple online wallets from the OS of multiple hosts or not.
Hope it helps someone.

4 Likes

Nice, you can upload it to.

Or link to it in the readme.md on grin Hub.

3 Likes

Finally, I could also ask chatgpt to write another script to check mass grin wallets and send email periodically with crontab
Requirement:

  • jq package
  • input file: grin_wallet_addresses.txt which has a list of wanted addresses
#!/bin/bash

# Set the recipient's email address
recipient_email="support@grinbux.com"

# Set the sender's name and email address
sender_name="Grin Archive Node Chicago"
sender_email="support@grinbux.com"

# Get current date and time in UTC
current_datetime=$(date -u +"%Y-%m-%d %H:%M:%S UTC")

# Define the subject of the email
email_subject="Grin Wallets Check - $current_datetime"

# Read the list of Grin wallet addresses from an external file
wallet_addresses_file="grin_wallet_addresses.txt"
wallet_addresses=($(cat "$wallet_addresses_file"))

# Initialize a variable to store the email content
email_content=""

# Initialize a variable to store the terminal output
terminal_output=""

# Loop through each wallet address and check its status
for grin_address in "${wallet_addresses[@]}"; do
    response=$(curl -s "https://grinnode.live:8080/walletcheck/$grin_address")
    is_wallet_valid=$(echo "$response" | jq -r '.isWalletValid')

    if [ "$is_wallet_valid" == "true" ]; then
        result="Grin address $grin_address is online."
    elif [ "$is_wallet_valid" == "false" ]; then
        result="Grin address $grin_address is not online."
    else
        result="Unable to determine status for Grin address $grin_address."
    fi

    email_content+="\n$result"
    terminal_output+="\n$result"
done

# Display the results in the terminal
echo -e "Grin Wallets Check Results:$terminal_output"

# Send the email with the results
echo -e "$email_content" | mail -s "$email_subject" -a "From: $sender_name <$sender_email>" "$recipient_email"

Result:

It would be also helpful to re-write this script to be using your own node.
https://grinnode.live:8080/walletcheck is a temporary solution but dont rely on it for production use as this is only a free service.

1 Like

I haven’t played around wallet API before, do you have any tips that I can build my own?

Cool and useful!
Indeed would be nice to run it on your own node or to have the option to try it via tor:
http://grinchck.ahcbagldgzdpa74g2mh74fvk5zjzpfjbvgqin6g3mfuu66tynv2gkiid.onion
Not sure it it is possible, I think @davidtavarez did not include an API, but you can ask.
It is possible to use curl via tor:

Ultimately it would be three lines you can chose from, 1) using your own node, 2) using grin node or 3) using tor. Users can just out-comment a line to chose their option

Here you can check how to use it: https://github.com/davidtavarez/GrinPP-CLI/blob/master/src/modules/utils/grinchck.py

for api_url you can use https://grinchck.uber.space/ I think

the code is here: https://github.com/davidtavarez/grinaddresschecker/blob/master/check/index.php

one may will have to change the params.

2 Likes