Created
June 5, 2012 03:04
-
-
Save pjxiao/2872324 to your computer and use it in GitHub Desktop.
tail multiple server log
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 | |
# ref http://mbkzmks.blogspot.jp/2011/02/tail.html | |
# log file path | |
FILE=$1 | |
# server addresses | |
SERVERS=( server1 server2 server3 ) | |
# ssh processes | |
SSH_PROCESSES=( ) | |
# check number of arguments. | |
if [ $# -ne 1 ]; then | |
echo 'specify path of log file.' | |
exit 1 | |
fi | |
# trap kill signal | |
trap 'final; exit 0' 1 2 3 15 | |
# kill ssh processes | |
function final { | |
for pid in ${SSH_PROCESSES[@]}; do | |
# send kill signal | |
kill ${pid} | |
done | |
} | |
# start ssh processes | |
for server in ${SERVERS[@]}; do | |
ssh $server tail -f $FILE & | |
SSH_PROCESSES=( ${SSH_PROCESSES[@]} $! ) | |
done | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment