Skip to content

Instantly share code, notes, and snippets.

@AndrewWestberg
Created January 12, 2020 02:25
Show Gist options
  • Save AndrewWestberg/e849237a188a50d6c1351a7b7d2ef0cc to your computer and use it in GitHub Desktop.
Save AndrewWestberg/e849237a188a50d6c1351a7b7d2ef0cc to your computer and use it in GitHub Desktop.
Check the yaml file for valid peers before starting jormungandr
#!/bin/bash
cp /home/westbam/cardano/itn_rewards_v1-config.yaml /home/westbam/cardano/itn_rewards_v1-config.yaml.new
# find all addresses that are not commented out
sed -e '/ address/!d' -e '/^[[:space:]]*#/d' -e '/Brainy/d' -e 's@^.*/ip./\([^/]*\)/tcp/\([0-9]*\).*@\1 \2@' /home/westbam/cardano/itn_rewards_v1-config.yaml | \
while read addr port
do
echo "Checking $addr:$port"
RESULT=$(tcpping -x 1 $addr $port)
echo "$RESULT"
if [[ $RESULT == *"open"* ]]; then
echo "Valid Peer"
else
# comment out the line
sed -i -e "/.*$addr\/tcp\/$port/,+1 s/^/#&/" /home/westbam/cardano/itn_rewards_v1-config.yaml.new
echo "Invalid Peer"
fi
done
# find all addresses that are commented out
sed -e '/ address/!d' -e '/^[[:space:]]*#/!d' -e '/Brainy/d' -e 's@^.*/ip./\([^/]*\)/tcp/\([0-9]*\).*@\1 \2@' /home/westbam/cardano/itn_rewards_v1-config.yaml | \
while read addr port
do
echo "Checking $addr:$port"
RESULT=$(tcpping -x 1 $addr $port)
echo "$RESULT"
if [[ $RESULT == *"open"* ]]; then
sed -i -e "/.*$addr\/tcp\/$port/,+1 s/^#//" /home/westbam/cardano/itn_rewards_v1-config.yaml.new
echo "Valid Peer"
else
echo "Invalid Peer"
fi
done
mv /home/westbam/cardano/itn_rewards_v1-config.yaml.new /home/westbam/cardano/itn_rewards_v1-config.yaml
@AndrewWestberg
Copy link
Author

Dependencies:

$ sudo apt-get install tcptraceroute
$ cd /usr/bin
$ sudo wget http://www.vdberg.org/~richard/tcpping
$ sudo chmod 755 tcpping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment