Skip to content

Instantly share code, notes, and snippets.

@JohnKim
Created April 2, 2013 00:53
Show Gist options
  • Save JohnKim/5289100 to your computer and use it in GitHub Desktop.
Save JohnKim/5289100 to your computer and use it in GitHub Desktop.
여러대의 서버에 같은 쉘명령을 한번에 실행하기 (from http://www.powerbox.pe.kr/351)
### cmd.sh
#!/bin/sh
HOSTLIST=hostlist.dat
if [ ! -n "$1" ]
then
echo "usage: $0 \"command arg1 arg2 ... \""
exit 1
fi
for i in `cat ~/$HOSTLIST`
do
echo $i "$*"
ssh $i "$*"
done
### hostlist.dat
ip또는 hostname
ip또는 hostname
ip또는 hostname
### mcp.sh
#!/bin/sh
HOSTLIST=~/hostlist.dat
if [ ! -n "$1" ]
then
echo "usage: $0 \"copy-file-name\""
exit 1
fi
for i in `cat $HOSTLIST`
do
echo $i "$*"
scp $1 $i:$1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment