From bash you can (save in ~/.bashrc
or something):
function create-follower () {
local _NAME=$1;
local _USER=$2;
local _HOST=$3;
local _PATH=$4;
if ! [ "${_NAME}" ]\
|| ! [ "${_USER}" ]\
|| ! [ "${_HOST}" ]\
|| ! [ "${_PATH}" ] ; then
{ echo "Cannot create log follower." ;
echo;
echo "Usage: create-follower NAME USER HOST LOG-FILE";
} >&2;
return 1 ;
fi ;
eval "function ${_NAME}(){ ssh ${_USER}@${_HOST} tail -f \"${_PATH}\" & }"
}
function activate-followers () {
if (( $# < 1 )) ; then
{ echo "You must specify at least one follower to use" ;
echo ;
echo "Usage:" ;
echo " activate-followers follower1 [follower2 ... followerN]";
} >&2;
return 1 ;
fi ;
for FOLLOW in "${@}" ; do
${FOLLOW} ;
done ;
wait;
}
function stop-followers () {
if [ "$(jobs)" ] ; then
kill -9 $(jobs | perl -pe 's/\[([0-9]+)\].*/%$1/') ;
fi ;
}
And then from your shell, define the logs you want to follow:
[dsm@localhost:~]$ create-follower test1 user1 localhost /tmp/log-1.txt
[dsm@localhost:~]$ create-follower test2 user2 otherhost /tmp/log-2.txt
[dsm@localhost:~]$ create-follower test2 user3 remotebox /tmp/log-3.txt
Now, activate the followers:
[dsm@localhost:~]$ activate-followers test1 test2 test3
To get out of the function use CTRL+C
, and to stop the backgrounded processes use:
[dsm@localhost:~]$ stop-followers
NOTE 1: This assumes public key authentication has been set up for your boxes.
NOTE 2: You will have to kill all the jobs that are left running after quitting the activate-followers function. You may want to do this manually as the function provided does a brute force kill on ALL backgrounded jobs
NOTE 3: This assumes a working unix-like environment, which you can get by installing cygwin
Who says you can't do lisp in shellscript ;-)