Skip to content

Instantly share code, notes, and snippets.

@vagnerd
Last active May 24, 2019 19:18
Show Gist options
  • Save vagnerd/b135bdcee3ccd25ddc938303759c6d27 to your computer and use it in GitHub Desktop.
Save vagnerd/b135bdcee3ccd25ddc938303759c6d27 to your computer and use it in GitHub Desktop.
#!/bin/bash
##
## Run multiple http servers (simple) on tmux
##
## http://oi66.tinypic.com/15x6dte.jpg - script run on multiple sessions
## http://oi63.tinypic.com/28sm0t4.jpg - testing all http servers
## https://stackoverflow.com/questions/16325449/how-to-send-a-command-to-all-panes-in-tmux - send command to all panes
TMP_HTTPD_DIR="/tmp/httpd_sh_dirs"
mkdir -p $TMP_HTTPD_DIR
echo "Starting http script server"
sleep `shuf -i1-10 -n1`
for XPORT in {8085..8092}; do
echo "checking available port"
sleep `shuf -i1-3 -n1`
PORT_USE=`netstat -an --tcp | grep LISTEN | awk '{ print $4 }' | grep $XPORT | cut -d\: -f2`
if [ $PORT_USE ]; then
echo "$PORT_USE port in use"
else
mkdir -p $TMP_HTTPD_DIR/$XPORT
cd $TMP_HTTPD_DIR/$XPORT
echo "WEBSERVER TEST - $XPORT" > index.html
python3 -m http.server $XPORT
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment