-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCp2Nodes
executable file
·81 lines (70 loc) · 2.98 KB
/
Cp2Nodes
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#**************************************************************
# EPPIC Pre-Computation Script
# Author : Kumaran Baskaran
# Date : 05/07/2013
#***************************************************************
CONCURRENCY=4
help=" Usage: $0 \n
Script to copy files to all nodes in cluster. Output and error are logged to log directory. Use chk_err.sh and chk_out.sh to check them.\n
Performs a 'cp -R' pulling files from a common NFS file system to the nodes.\n
The copy will be done concurrently from $CONCURRENCY nodes at a time. Unless another concurrency valued specified in third parameter.\n
\t\t [ -s <dir> : Source Directory (must be in an nfs exported file system from the head nodes)\n
\t\t -d <dir> : Destination Directory ( must be local to the node. Can only be of form /scratch/<YOUR_FOLDER> )\n
\t\t -n <file> : File specifying set of host nodes where the files are to be copied \n
\t\t -l <dir> : Logs directory \n
\t\t [-c <int>] : Concurrency value, number of host nodes where the files are copied concurrently ] \n
Example: ./cp2cluster -s /gpfs/home/duarte_j/data/uniprot_2013_02 -d /scratch/biyani_n -n /blast/merlin-nodes.list -l /blast/copy-logs/\n"
while getopts :s:d:n:l:c:h option
do
case "${option}"
in
s) srcdir=${OPTARG};;
d) destdir=${OPTARG};;
n) hfile=${OPTARG};;
l) logsdir=${OPTARG};;
c) CONCURRENCY=${OPTARG};;
h) echo -e $help;;
\?) print >&2 $help
exit 1;;
:) echo "`date +%d/%m/%y-%H:%M:%S` ERROR: Option -$OPTARG requires an argument." >&2
exit 1;;
esac
done
if [ -z $srcdir ] || [ -z $destdir ] || [ -z $hfile ] || [ -z $CONCURRENCY ] || [ -z $logsdir ]
then
echo -e "\n`date +%d/%m/%y-%H:%M:%S` INFO: ---- SOME OPTIONS NOT SPECIFIED CORRECTLY ---- " >&2
echo -e $help
exit 1
fi
if [ ! -f $hfile ]
then
echo "`date +%d/%m/%y-%H:%M:%S` ERROR: File $hfile can\'t be read" >&2
exit 1
fi
if [ ! -d $logsdir ]
then
mkdir -p $logsdir
fi
allnodes=`cat $hfile`
echo "`date +%d/%m/%y-%H:%M:%S` INFO: Copy being done from $CONCURRENCY nodes at a time."
cmd="cp -vR $srcdir $destdir"
count=1
# deleting old output/error logs
rm -f $logsdir/*.out $logsdir/*.err
for node in $allnodes
do
mod=`expr $count % $CONCURRENCY`
if [ "$mod" -ne "0" ]
then
echo "`date +%d/%m/%y-%H:%M:%S` INFO: Copying $node..."; ssh $node $cmd 1>$logsdir/$node.out 2>$logsdir/$node.err &
# we introduce a 0.1s delay between the start of each ssh job
# this speeds up considerably the ssh startup as the mount requests from nodes don't come all exactly at the same moment
sleep 0.1
else
echo "`date +%d/%m/%y-%H:%M:%S` INFO: Copying $node..."; ssh $node $cmd 1>$logsdir/$node.out 2>$logsdir/$node.err
fi
count=`expr $count + 1`
done
# making log files writable (and removable) to the group
chmod g+rw $logsdir/*.out $logsdir/*.err