# Daily monitor Grin nodes/wallets status by email

**URL:** <https://forum.grin.mw/t/daily-monitor-grin-nodes-wallets-status-by-email/10703>\
**Category:** Tech Support\
**Created:** [August 25, 2023, 5:46pm UTC](https://forum.grin.mw/t/daily-monitor-grin-nodes-wallets-status-by-email/10703 "2023-08-25T17:46:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![noobvie](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@noobvie](https://forum.grin.mw/u/noobvie)\
**Post date:** [August 25, 2023, 5:46pm UTC](https://forum.grin.mw/t/daily-monitor-grin-nodes-wallets-status-by-email/10703/1 "2023-08-25T17:46:13Z")

</div>

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:

```auto
#!/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:

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

```

Result:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/grin/original/2X/3/312b19f89c896c9c7f5f2d30e305b783a4939718.png)

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.

---

<div class="post-metadata">

**Author:** ![Anynomous](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.grin.mw/anynomous/32/2928_2.png) [@Anynomous](https://forum.grin.mw/u/Anynomous)\
**Post date:** [August 26, 2023, 11:24am UTC](https://forum.grin.mw/t/daily-monitor-grin-nodes-wallets-status-by-email/10703/2 "2023-08-26T11:24:34Z")

</div>

Nice, you can upload it to.

> <https://github.com/grincc/hub/tree/main/scripts>
>
> //github.com/grincc/hub/tree/main/scripts

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

---

<div class="post-metadata">

**Author:** ![noobvie](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@noobvie](https://forum.grin.mw/u/noobvie)\
**Post date:** [August 28, 2023, 12:35am UTC](https://forum.grin.mw/t/daily-monitor-grin-nodes-wallets-status-by-email/10703/3 "2023-08-28T00:35:07Z")

</div>

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

```auto
#!/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:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/grin/original/2X/9/9af8b5c5b5f1c7b243de96648173d93a5e80b81e.png)

---

<div class="post-metadata">

**Author:** ![mcm-mike](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.grin.mw/mcm-mike/32/3492_2.png) [@mcm-mike](https://forum.grin.mw/u/mcm-mike)\
**Post date:** [August 28, 2023, 1:26pm UTC](https://forum.grin.mw/t/daily-monitor-grin-nodes-wallets-status-by-email/10703/4 "2023-08-28T13:26:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![noobvie](https://avatars.discourse-cdn.com/v4/letter/n/9d8465/32.png) [@noobvie](https://forum.grin.mw/u/noobvie)\
**Post date:** [August 28, 2023, 2:00pm UTC](https://forum.grin.mw/t/daily-monitor-grin-nodes-wallets-status-by-email/10703/5 "2023-08-28T14:00:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anynomous](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.grin.mw/anynomous/32/2928_2.png) [@Anynomous](https://forum.grin.mw/u/Anynomous)\
**Post date:** [August 29, 2023, 7:24am UTC](https://forum.grin.mw/t/daily-monitor-grin-nodes-wallets-status-by-email/10703/6 "2023-08-29T07:24:41Z")

</div>

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](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:

> **[Making Tor Requests with command-line cURL](https://www.devdungeon.com/content/making-tor-requests-command-line-curl)**
>
> Learn how to make requests on Tor using cURL on the command line.

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

---

<div class="post-metadata">

**Author:** ![davidtavarez](https://avatars.discourse-cdn.com/v4/letter/d/3ab097/32.png) [@davidtavarez](https://forum.grin.mw/u/davidtavarez)\
**Post date:** [August 29, 2023, 8:34am UTC](https://forum.grin.mw/t/daily-monitor-grin-nodes-wallets-status-by-email/10703/7 "2023-08-29T08:34:58Z")

</div>

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

for `api_url` you can use [https://grinchck.uber.space/](https://grinchck.uber.space/) I think

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

one may will have to change the params.
