Last active
February 10, 2016 18:09
-
-
Save saliceti/5b0db8e4750e77a40e84 to your computer and use it in GitHub Desktop.
Capture TCP connections
This file contains 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 | |
set -x | |
GATEWAY=52.48.251.177 | |
TMP_DIR=/tmp/flow_log | |
VM_LIST_FILE=${TMP_DIR}/vm_list.txt | |
IPTABLES_INSTALL_OUTPUT="iptables -A OUTPUT -m state --state NEW -j LOG --log-prefix '[flow-logs-output] '" | |
IPTABLES_INSTALL_INPUT="iptables -A INPUT -m state --state NEW -j LOG --log-prefix '[flow-logs-input] '" | |
IPTABLES_REMOVE_OUTPUT="iptables -D OUTPUT -m state --state NEW -j LOG --log-prefix '[flow-logs-output] '" | |
IPTABLES_REMOVE_INPUT="iptables -D INPUT -m state --state NEW -j LOG --log-prefix '[flow-logs-input] '" | |
run_remote() { | |
job=$1 | |
command=$2 | |
bosh ssh --gateway_host ${GATEWAY} --gateway_user vcap --default_password a $job $command | |
} | |
create_vm_list() { | |
echo Fetching VM list... 1>&2 | |
bosh vms 2>&1 | grep running | awk '{print $2}' > ${VM_LIST_FILE} | |
} | |
run_parallel() { | |
command=$1 | |
echo Running on ${vm_list[@]} VMs: ${command} | |
while read job ; do | |
output_file=${TMP_DIR}/$(echo ${job} | tr / -).log | |
echo Writing output to ${output_file}... | |
run_remote ${job} "${command}" > ${output_file} & | |
sleep 1 | |
done < ${VM_LIST_FILE} | |
} | |
# Init | |
mkdir -p ${TMP_DIR} | |
create_vm_list | |
# Run | |
run_parallel "cat /etc/passwd" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment