dtr35t1.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 # check to see if there's already another instance of this script running -- that is a process with
4 # the name but not being edited
5 
6 scriptdir=/home/lbnedaq/trj
7 remotemachine=lbnedaq6
8 remoteuser=lbnedaq
9 inputremoteuser=${remoteuser}@${remotemachine}
10 ftpuser=lbnedata
11 inputremote=/storage/data
12 inputtransferred=/storage/data/transferred
13 localincomingdir=/data/lbnedaq/data/incoming_files
14 # the same directory but its name as mounted on lbnedaq6 and lbnedaq7
15 localincomingdir_rem=/data2/lbnedaq/data/incoming_files
16 localtransdir=/data/lbnedaq/data/transferring_files
17 localdonedir=/data/lbnedaq/data/transferred_files
18 locallogdir=/data/lbnedaq/data/transfer_logs
19 localfaildir=/data/lbnedaq/data/failed_files
20 #dropboxdir=/pnfs/lbne/scratch/lbnepro/dropbox/data
21 dropboxdir=/data/lbnepro/dropbox/data
22 filelistdir=/data/lbnedaq/data/filelist
23 
24 ntrylimit=10
25 
26 myscriptname=`basename $0 .sh`
27 # echo $myscriptname
28 
29 ps aux | grep ${myscriptname} | grep -v emacs | grep -v vim
30 
31 numprocsp2=`ps aux | grep ${myscriptname} | grep -v emacs | grep -v vim | wc -l`
32 
33 # echo $numprocsp2
34 
35 if [ $numprocsp2 -gt 3 ]; then
36  exit 0
37 fi
38 
39 # get our Kerberos ticket
40 
41 #KEYTAB=/var/adm/krb5/`/usr/krb5/bin/kcron -f`
42 KEYTAB=/var/adm/krb5/lbnedaq.keytab
43 KEYUSE=`/usr/krb5/bin/klist -k ${KEYTAB} | grep FNAL.GOV | head -1 | cut -c 5- | cut -f 1 -d /`
44 /usr/krb5/bin/kinit -5 -A -kt ${KEYTAB} ${KEYUSE}/dune/`hostname`@FNAL.GOV
45 #/usr/krb5/bin/kx509
46 
47 phost=lbnedaq@lbnegpvm01.fnal.gov
48 
49 read tmpstring < ${scriptdir}/fstring.txt
50 
51 for filename in `ssh ${inputremoteuser} ls ${inputremote}/lbne_r*.root | grep -v lbne_r-_sr-_`
52 do
53 
54 # needed for ftp -- put files in the right directory
55  cd ${localincomingdir}
56 
57  fbase=`basename $filename`
58  for itry in `seq 1 $ntrylimit`
59  do
60 
61  remotechecksum=`ssh ${inputremoteuser} nice cksum ${filename}`
62  checksumvalue_inputremote=`echo $remotechecksum | cut -f 1 -d " "`
63  checksumsize_inputremote=`echo $remotechecksum | cut -f 2 -d " "`
64  success=0
65 
66 # first attempt -- use scp to pull the file
67 # scp -q ${inputremoteuser}:${filename} $localincomingdir/
68 
69 # second attempt -- push the file with cp using the disk mount on the gateway
70 # ssh ${inputremoteuser} cp -f ${filename} ${localincomingdir_rem}/
71 
72 # third attempt -- use ftp
73 
74 ftp -n $remotemachine <<EOF
75 quote USER ${ftpuser}
76 quote PASS ${tmpstring}
77 binary
78 get ${fbase}
79 exit
80 EOF
81  if [ $? -ne 0 ]
82  then
83  continue
84  fi
85  localchecksum=`cksum $localincomingdir/$fbase`
86  checksumvalue_inputlocal=`echo $localchecksum | cut -f 1 -d " "`
87  checksumsize_inputlocal=`echo $localchecksum | cut -f 2 -d " "`
88 
89  echo $fname
90  echo $checksumvalue_inputlocal
91  echo $checksumvalue_inputremote
92  echo $checksumsize_inputlocal
93  echo $checksumsize_inputremote
94 
95  if [ $checksumvalue_inputlocal -eq $checksumvalue_inputremote ]
96  then
97  if [ $checksumsize_inputlocal -eq $checksumsize_inputremote ]
98  then
99  echo "Succeeded in copying $fbase"
100  mv -v $localincomingdir/$fbase $localtransdir
101  ssh $inputremoteuser mv $filename $inputtransferred
102  success=1
103  break
104  fi
105  fi
106  if [ $success -ne 1 ]
107  then
108  mv -v $localincomingdir/$fbase $localfaildir
109  fi
110  done
111 done
112 
113 $scriptdir/make_metadata35t_declare.sh $localtransdir $localfaildir $scriptdir $filelistdir
114 
115 # to update -- need to check the checksum and retry here if it fails
116 # only mv the file to the localdonedir if the copy succeded. Otherwise we'll try again when
117 # this script runs again, leaving the file in the localtransdir
118 # consider using dccp here instead in order to get checksum validation
119 
120 cd $localtransdir
121 for filename in `ls *.root`
122 do
123 # temporary hack to keep a copy for the nearline monitor in the done directory
124  fbase=`basename $filename`
125  ln $fbase $localdonedir/$fbase
126 # the dropbox is read and cleaned up by user lbnepro so make sure it has permission to do so
127  chmod g+w $filename
128  mv -v $filename $dropboxdir
129  if [ $? -eq 0 ]
130  then
131 
132 # mv -v $filename $localdonedir
133  mv -v $filename.json $localdonedir
134  fi
135 done
136