#!/bin/bash
agregateResults (); { while read line; do echo "Program Output: $line"; done; }
clientCode (); { echo "I am client $(hostname)."; }
if [[ "${1}" == "client" ]]; then
clienCode
else
for server in ${*}; do
cat ${0} | ssh ${server} -s client
done | agregateResults
fi
agregateResults (); { while read line; do echo "Program Output: $line"; done; }
clientCode (); { echo "I am client $(hostname)."; }
if [[ "${1}" == "client" ]]; then
clienCode
else
for server in ${*}; do
cat ${0} | ssh ${server} -s client
done | agregateResults
fi
This is so freaking useful. I have servers across multiple domains and I need to run script to aggregate data from all of them, but I can't always count on network file systems being available, etc. This lets me have a script in once place and execute the same code everywhere without fumbling with copying it ahead of time, etc. It's so clean and easy.
When I try to find out how to do this with Python, I read all kinds of stuff about parallels, Paramiko, blah blah blah... it's all so complicated. There has to be a five-liner example out there somewhere of how to do the same kind of thing.
Started a code-golf at stackexchange for this one: http://codegolf.stackexchange.com/questions/20008/self-execute-over-ssh