Skip to content

Instantly share code, notes, and snippets.

@saliceti
Last active Feb 10, 2016
Embed
What would you like to do?
Capture TCP connections
#!/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