Skip to content

Instantly share code, notes, and snippets.

@jsidhu
Last active September 16, 2016 00:27
Show Gist options
  • Save jsidhu/4f8b94df1560c4ed0f23 to your computer and use it in GitHub Desktop.
Save jsidhu/4f8b94df1560c4ed0f23 to your computer and use it in GitHub Desktop.
bash tcp port check
timeout 1 bash -c 'cat < /dev/null > /dev/tcp/lmm-kafka-2.ash2.symcpe.net/9092'; echo "Port Check result: $?"
for x in $(cat x); do timeout 2 bash -c 'cat < /dev/null > /dev/tcp/'$x'/22' || echo "No SSH to $x"; done
@jsidhu
Copy link
Author

jsidhu commented Sep 16, 2016

#!/bin/bash

while true; do
for HOST in $(cat swift.nodes); do
    timeout 1 bash -c 'cat < /dev/null > /dev/tcp/'${HOST}'/6010';
    RESULT=$?
    if [ ${RESULT} -gt 0 ]; then
        echo "Failed to connect to ${HOST}"
    else
        echo -n "t"
    fi
    RESULT=$(curl -sL -w "%{http_code}\\n" "http://${HOST}:6010/" -o /dev/null)
    if [ ${RESULT} -ne 405 ]; then
        echo "Failed to connect to ${HOST}"
    else
        echo -n "c"
    fi

done
echo " done!"
sleep 1
done

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