1 |
#!/bin/bash
|
2 |
#---------------------------------------------------------------------------------------------------
|
3 |
# Rename an existing sample (so far all potentially exisiting catalog info will have to be redone)
|
4 |
# Careful to make sure CERN is working you need to activate the ssh tunnel:
|
5 |
#
|
6 |
# sshCernTunnel dtmit08
|
7 |
#
|
8 |
#---------------------------------------------------------------------------------------------------
|
9 |
CATALOG=~cmsprod/catalog
|
10 |
testTunnel=`ps auxw | grep -v grep | grep sshCernTunnel`
|
11 |
if [ "$testTunnel" == "" ]
|
12 |
then
|
13 |
echo " ERRO - it seems the cern ssh tunnel is not active"
|
14 |
echo " to start it use: sshCernTunnel dtmit08"
|
15 |
echo ""
|
16 |
exit 1
|
17 |
fi
|
18 |
domain=`echo $HOSTNAME | cut -d'.' -f2-100`
|
19 |
if [ "$domain" == "mit.edu" ]
|
20 |
then
|
21 |
# For MIT
|
22 |
SERVER="srm://se01.cmsaf.mit.edu:8443/srm/v2/server?SFN="
|
23 |
LOCATION="/mnt/hadoop/cms/store/user/paus"
|
24 |
LOCAL_LOCATION="/mnt/hadoop/cmsprod"
|
25 |
else
|
26 |
# For CERN
|
27 |
SERVER="srm://srm-cms.cern.ch:8443/srm/managerv2?SFN="
|
28 |
LOCATION="/castor/cern.ch/user/p/paus"
|
29 |
LOCAL_LOCATION="/data/hadoop/cmsprod"
|
30 |
fi
|
31 |
|
32 |
# For CERN
|
33 |
CERN_SERVER="srm://srm-cms.cern.ch:8443/srm/managerv2?SFN="
|
34 |
CERN_LOCATION="/castor/cern.ch/user/p/paus"
|
35 |
CERN_LOCAL_LOCATION="/data/hadoop/cmsprod"
|
36 |
|
37 |
klist -s
|
38 |
if [ $? != 0 ]; then
|
39 |
kinit -f
|
40 |
fi
|
41 |
|
42 |
BOOK="$1"
|
43 |
SOURCE="$2"
|
44 |
TARGET="$3"
|
45 |
|
46 |
echo ""
|
47 |
echo "Trying to rename sample: $SOURCE to $TARGET"
|
48 |
echo " at CERN: ${CERN_SERVER}${CERN_LOCATION}/$BOOK"
|
49 |
echo " at MIT: ${SERVER}${LOCATION}/$BOOK"
|
50 |
echo ""
|
51 |
echo ""
|
52 |
|
53 |
# Start with CERN
|
54 |
|
55 |
sourceExists=`srmls -recursion_depth=0 ${CERN_SERVER}${CERN_LOCATION}/${BOOK}/$SOURCE 2> /dev/null`
|
56 |
echo " Existing - source (CERN): $sourceExists"
|
57 |
targetExists=`srmls -recursion_depth=0 ${CERN_SERVER}${CERN_LOCATION}/${BOOK}/$TARGET 2> /dev/null`
|
58 |
echo " Existing - target (CERN): $targetExists"
|
59 |
|
60 |
# first the original files
|
61 |
if [ ".$sourceExists" != "." ] && [ ".$targetExists" == "." ]
|
62 |
then
|
63 |
echo " Move data files at CERN"
|
64 |
move ${CERN_LOCATION}/${BOOK}/$SOURCE ${CERN_LOCATION}/${BOOK}/$TARGET
|
65 |
# next are the cern catalogs
|
66 |
existSource=`ssh localhost -p 2222 ls -1 catalog/cern/${BOOK}/$SOURCE 2> /dev/null`
|
67 |
if [ "$existSource" != "" ]
|
68 |
then
|
69 |
echo " Moving catalogs at CERN"
|
70 |
ssh localhost -p 2222 \
|
71 |
"cd catalog/cern/${BOOK}; mv $SOURCE $TARGET; cd $TARGET; repstr $SOURCE $TARGET Filesets RawFiles.??"
|
72 |
else
|
73 |
echo " No catalogs found at CERN"
|
74 |
fi
|
75 |
else
|
76 |
echo " No data files found at CERN"
|
77 |
fi
|
78 |
|
79 |
# now the local CERN files
|
80 |
existSource=`ssh localhost -p 2222 ls -1 ${CERN_LOCAL_LOCATION}/${BOOK}/$SOURCE 2> /dev/null`
|
81 |
existTarget=`ssh localhost -p 2222 ls -1 ${CERN_LOCAL_LOCATION}/${BOOK}/$TARGET 2> /dev/null`
|
82 |
if [ "$existSource" != "" ] && [ "$existTarget" == "" ]
|
83 |
then
|
84 |
echo " Moving local samples: mv ${CERN_LOCAL_LOCATION}/${BOOK}/$SOURCE ${CERN_LOCAL_LOCATION}/${BOOK}/$TARGET"
|
85 |
ssh localhost -p 2222 mv ${CERN_LOCAL_LOCATION}/${BOOK}/$SOURCE ${CERN_LOCAL_LOCATION}/${BOOK}/$TARGET
|
86 |
# next are the cern local catalogs
|
87 |
existSource=`ssh localhost -p 2222 ls -1 catalog/local/${BOOK}/$SOURCE 2> /dev/null`
|
88 |
if [ "$existSource" != "" ]
|
89 |
then
|
90 |
echo " Moving local catalogs at CERN"
|
91 |
ssh localhost -p 2222 \
|
92 |
"cd catalog/local/${BOOK}; mv $SOURCE $TARGET; cd $TARGET; repstr $SOURCE $TARGET Filesets RawFiles.??"
|
93 |
else
|
94 |
echo " No local catalogs found at CERN"
|
95 |
fi
|
96 |
else
|
97 |
echo " No local data files found at CERN"
|
98 |
fi
|
99 |
|
100 |
# Continue with MIT
|
101 |
|
102 |
sourceExists=`srmls -recursion_depth=0 ${SERVER}${LOCATION}/${BOOK}/$SOURCE 2> /dev/null`
|
103 |
echo " Existing - source (MIT): $sourceExists"
|
104 |
targetExists=`srmls -recursion_depth=0 ${SERVER}${LOCATION}/${BOOK}/$TARGET 2> /dev/null`
|
105 |
echo " Existing - target (MIT): $targetExists"
|
106 |
|
107 |
# first the original files
|
108 |
if [ ".$sourceExists" != "." ] && [ ".$targetExists" == "." ]
|
109 |
then
|
110 |
echo " Moving data files at MIT"
|
111 |
move ${LOCATION}/${BOOK}/$SOURCE ${LOCATION}/${BOOK}/$TARGET
|
112 |
# next are the catalogs
|
113 |
cd $CATALOG/t2mit/$BOOK
|
114 |
if [ -d $SOURCE ]
|
115 |
then
|
116 |
echo " Moving catalogs at MIT"
|
117 |
mv $SOURCE $TARGET
|
118 |
cd $TARGET
|
119 |
repstr $SOURCE $TARGET Filesets RawFiles.??
|
120 |
else
|
121 |
echo " No catalogs found at MIT"
|
122 |
fi
|
123 |
# correct our central sample database
|
124 |
echo " Updating our central sample database"
|
125 |
repstr $SOURCE $TARGET ~cmsprod/public_html/$BOOK/Productions.*
|
126 |
else
|
127 |
echo " No data files found at MIT"
|
128 |
fi
|
129 |
|
130 |
# now the local files
|
131 |
if [ -d "${LOCAL_LOCATION}/${BOOK}/$SOURCE" ] && ! [ -d "${LOCAL_LOCATION}/${BOOK}/$TARGET" ]
|
132 |
then
|
133 |
echo " Moving local samples at MIT: move ${LOCAL_LOCATION}/${BOOK}/$SOURCE ${LOCAL_LOCATION}/${BOOK}/$TARGET"
|
134 |
move ${LOCAL_LOCATION}/${BOOK}/$SOURCE ${LOCAL_LOCATION}/${BOOK}/$TARGET
|
135 |
cd $CATALOG/local/$BOOK
|
136 |
if [ -d $SOURCE ]
|
137 |
then
|
138 |
echo " Moving local catalogs at MIT"
|
139 |
mv $SOURCE $TARGET
|
140 |
cd $TARGET
|
141 |
repstr $SOURCE $TARGET Filesets RawFiles.??
|
142 |
else
|
143 |
echo " No local catalogs found at MIT"
|
144 |
fi
|
145 |
else
|
146 |
echo " No local data files found at MIT"
|
147 |
fi
|
148 |
|
149 |
exit 0
|