launch.sh 994 Bytes
Newer Older
1
2
3
##################################################################################
# User runs this script to launch distrobited jobs on cluster
##################################################################################
4
5
6
7
script_path=$1
script_file=$2
user_name=$3
ssh_key=$4
8
9

server_count=$(awk 'NR==1 {print $3}' ip_config.txt)
10
machine_count=$(awk 'END{print NR}' ip_config.txt)
11
12
13
14
15
16
17
18
19
20
21

# run command on remote machine
LINE_LOW=2
LINE_HIGH=$(awk 'END{print NR}' ip_config.txt)
let LINE_HIGH+=1
s_id=0
while [ $LINE_LOW -lt $LINE_HIGH ]
do
    ip=$(awk 'NR=='$LINE_LOW' {print $1}' ip_config.txt)
    let LINE_LOW+=1
    let s_id+=1
22
23
24
25
26
27
28
    if test -z "$ssh_key" 
    then
        ssh $user_name@$ip 'cd '$script_path'; '$script_file' '$s_id' '$server_count' '$machine_count'' &
    else
        ssh -i $ssh_key $user_name@$ip 'cd '$script_path'; '$script_file' '$s_id' '$server_count' '$machine_count'' &
    fi
    
29
30
31
done

# run command on local machine
32
$script_file 0 $server_count $machine_count