ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/renameSample.sh
Revision: 1.7.2.1
Committed: Fri Jun 14 19:34:39 2013 UTC (11 years, 10 months ago) by paus
Content type: application/x-sh
Branch: Mit_025c_branch
CVS Tags: Mit_025c_branch2
Changes since 1.7: +106 -86 lines
Log Message:
PrepareForBackportVersion3.

File Contents

# User Rev Content
1 paus 1.1 #!/bin/bash
2     #---------------------------------------------------------------------------------------------------
3 paus 1.6 # Rename an existing sample (so far all potentially exisiting catalog info will have to be redone)
4 paus 1.7.2.1 # Careful to make sure CERN is working you need to activate the ssh tunnel:
5     #
6     # sshCernTunnel dtmit08
7     #
8 paus 1.1 #---------------------------------------------------------------------------------------------------
9 paus 1.7.2.1 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 paus 1.7 domain=`echo $HOSTNAME | cut -d'.' -f2-100`
19     if [ "$domain" == "mit.edu" ]
20     then
21     # For MIT
22 paus 1.7.2.1 SERVER="srm://se01.cmsaf.mit.edu:8443/srm/v2/server?SFN="
23     LOCATION="/mnt/hadoop/cms/store/user/paus"
24 paus 1.7 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 paus 1.7.2.1 # 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 paus 1.6 klist -s
38     if [ $? != 0 ]; then
39     kinit -f
40     fi
41 paus 1.1
42 paus 1.7.2.1 BOOK="$1"
43     SOURCE="$2"
44     TARGET="$3"
45 paus 1.1
46 paus 1.6 echo ""
47     echo "Trying to rename sample: $SOURCE to $TARGET"
48 paus 1.7.2.1 echo " at CERN: ${CERN_SERVER}${CERN_LOCATION}/$BOOK"
49     echo " at MIT: ${SERVER}${LOCATION}/$BOOK"
50 paus 1.6 echo ""
51     echo ""
52    
53 paus 1.7.2.1 # 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 paus 1.1
60 paus 1.2 # first the original files
61 paus 1.1 if [ ".$sourceExists" != "." ] && [ ".$targetExists" == "." ]
62     then
63 paus 1.7.2.1 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 paus 1.2 fi
78 paus 1.1
79 paus 1.7.2.1 # 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 paus 1.2 then
84 paus 1.7.2.1 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 paus 1.1 fi
99    
100 paus 1.7.2.1 # 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 paus 1.1 then
110 paus 1.7.2.1 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 paus 1.1 fi
129    
130 paus 1.7.2.1 # now the local files
131     if [ -d "${LOCAL_LOCATION}/${BOOK}/$SOURCE" ] && ! [ -d "${LOCAL_LOCATION}/${BOOK}/$TARGET" ]
132 paus 1.1 then
133 paus 1.7.2.1 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 paus 1.1 fi
148    
149     exit 0