Created
June 20, 2025 16:17
-
-
Save slavafomin/9eda588b2ec43895742aa0d422973316 to your computer and use it in GitHub Desktop.
Script to monitor TON Node blocks import status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to process log and get human-readable date | |
get_gen_utime() { | |
# Get the maximum seqno from the log | |
max_seqno=$(tail -n 10 /var/ton-work/log* | grep "Imported archive" | grep -o "mc_seqno=[0-9]*" | cut -d'=' -f2 | sort -n | tail -n 1) | |
# Call the API and store gen_utime in a variable | |
gen_utime=$(curl -s "https://toncenter.com/api/v3/blocks?workchain=-1&shard=8000000000000000&seqno=${max_seqno}&limit=1" | jq -r '.blocks[0].gen_utime') | |
# Convert gen_utime to human-readable date | |
if [ -n "$gen_utime" ]; then | |
human_readable_date=$(date -d "@${gen_utime}" '+%Y-%m-%d %H:%M:%S %Z') | |
echo "$human_readable_date" | |
else | |
echo "Error: Could not retrieve gen_utime from API" | |
fi | |
} | |
# Check for -w or --watch argument | |
if [[ "$1" == "-w" || "$1" == "--watch" ]]; then | |
while true; do | |
get_gen_utime | |
sleep 10 | |
done | |
else | |
get_gen_utime | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment