better
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source /root/rpc/.env
|
BASEPATH=/root/rpc
|
||||||
|
source $BASEPATH/.env
|
||||||
|
|
||||||
blacklist=("lighthouse" "prism" "beacon" "nimbus" "ws" "arbitrum-classic" "hagall" "public")
|
blacklist=("lighthouse" "prism" "beacon" "nimbus" "ws" "arbitrum-classic" "hagall" "public")
|
||||||
|
|
||||||
@@ -15,33 +16,73 @@ for part in "${parts[@]}"; do
|
|||||||
include=true
|
include=true
|
||||||
for word in "${blacklist[@]}"; do
|
for word in "${blacklist[@]}"; do
|
||||||
if echo "$path" | grep -qE "$word"; then
|
if echo "$path" | grep -qE "$word"; then
|
||||||
echo "The path $path contains a blacklisted word: $word"
|
#echo "The path $path contains a blacklisted word: $word"
|
||||||
include=false
|
include=false
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
#echo "include: $include; $DOMAIN$path"
|
#echo "include: $include; $DOMAIN$path"
|
||||||
if $include; then
|
if $include; then
|
||||||
echo "Querying $DOMAIN$path"
|
#echo "Querying $DOMAIN$path"
|
||||||
|
|
||||||
RPC_URL="https://$DOMAIN$path"
|
RPC_URL="https://$DOMAIN$path"
|
||||||
|
|
||||||
# Query the Ethereum JSON-RPC endpoint for the latest block timestamp
|
response_file=$(mktemp)
|
||||||
latest_block_timestamp=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' $RPC_URL | jq -r '.result.timestamp')
|
|
||||||
|
|
||||||
# Convert the latest block timestamp from hexadecimal to decimal
|
http_status_code=$(curl --ipv4 -m 1 -s -X POST -w "%{http_code}" -o "$response_file" -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' $RPC_URL)
|
||||||
latest_block_timestamp_decimal=$((16#$latest_block_timestamp))
|
|
||||||
|
|
||||||
# Get the current system time in seconds
|
if [ $? -eq 0 ]; then
|
||||||
current_time=$(date +%s)
|
# If successful, print the response
|
||||||
|
#echo "Curl request succeeded:"
|
||||||
|
#echo "$response"
|
||||||
|
|
||||||
# Calculate the difference between the latest block timestamp and the current system time
|
if [[ $http_status_code -eq 200 ]]; then
|
||||||
time_difference=$((current_time - latest_block_timestamp_decimal))
|
# Handle successful response (HTTP 200)
|
||||||
|
#echo "HTTP 200: Success"
|
||||||
|
# Read and output the response body from the temporary file
|
||||||
|
response=$(cat "$response_file")
|
||||||
|
|
||||||
# Print the time difference in seconds
|
latest_block_timestamp=$(echo "$response" | jq -r '.result.timestamp')
|
||||||
echo "Time difference between the latest block and current system time: $time_difference seconds"
|
|
||||||
|
|
||||||
fi
|
# Convert the latest block timestamp from hexadecimal to decimal
|
||||||
|
latest_block_timestamp_decimal=$((16#${latest_block_timestamp#0x}))
|
||||||
|
|
||||||
|
# Get the current system time in seconds
|
||||||
|
current_time=$(date +%s)
|
||||||
|
|
||||||
|
# Calculate the difference between the latest block timestamp and the current system time
|
||||||
|
time_difference=$((current_time - latest_block_timestamp_decimal))
|
||||||
|
|
||||||
|
if [ $time_difference -lt 60 ]; then
|
||||||
|
echo "$path: online"
|
||||||
|
else
|
||||||
|
|
||||||
|
formatted_time_difference=$(printf '%d years %d months %d weeks %d days %d hours %d minutes %d seconds\n' \
|
||||||
|
$((time_difference / 31536000)) \
|
||||||
|
$((time_difference % 31536000 / 2592000)) \
|
||||||
|
$((time_difference % 2592000 / 604800)) \
|
||||||
|
$((time_difference % 604800 / 86400)) \
|
||||||
|
$((time_difference % 86400 / 3600)) \
|
||||||
|
$((time_difference % 3600 / 60)) \
|
||||||
|
$((time_difference % 60)))
|
||||||
|
|
||||||
|
# Print the time difference in seconds
|
||||||
|
echo "$path: syncing ($formatted_time_difference)"
|
||||||
|
fi
|
||||||
|
elif [[ $http_status_code -eq 404 ]]; then
|
||||||
|
# Handle HTTP 404 error
|
||||||
|
echo "$path: offline"
|
||||||
|
else
|
||||||
|
# Handle other HTTP response codes
|
||||||
|
echo "Unexpected HTTP status code: $http_status_code"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# If the command failed (timed out), print an error message
|
||||||
|
echo "Error: Curl request timed out after 1 second"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm "$response_file"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user