-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.sh
executable file
·42 lines (32 loc) · 1.07 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
if [ "$2" = "" ]; then
echo "usage: $0 <hostname> <script> [argument] [...]"
exit 1
elif [ ! -f $2 ]; then
echo "error: file $2 not found"
exit 1
fi
query=$1
script="`realpath $2`"
shift
shift
server=`/opt/farm/mgr/farm-manager/internal/lookup-server.sh $query`
host=`/opt/farm/mgr/farm-manager/internal/decode.sh host $server`
port=`/opt/farm/mgr/farm-manager/internal/decode.sh port $server`
tag=`/opt/farm/mgr/farm-manager/internal/decode.sh tag $server`
if [ -x ~/.serverfarmer/hooks/ssh-accounting.sh ] && [ "$tag" != "" ]; then
~/.serverfarmer/hooks/ssh-accounting.sh start $tag
fi
sshkey=`/opt/farm/ext/keys/get-ssh-management-key.sh $host`
remote="`dirname $script`"
if [ "$remote" = "." ]; then
remote=`pwd`
fi
ssh -i $sshkey -p $port -o StrictHostKeyChecking=no root@$host mkdir -p $remote
if [[ $? = 0 ]]; then
scp -i $sshkey -P $port $script root@$host:$remote
ssh -i $sshkey -p $port -t root@$host "sh -c '$script $@'"
fi
if [ -x ~/.serverfarmer/hooks/ssh-accounting.sh ] && [ "$tag" != "" ]; then
~/.serverfarmer/hooks/ssh-accounting.sh stop $tag
fi