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
6 scriptdir=/home/lbnedaq/trj
9 inputremoteuser=${remoteuser}@${remotemachine}
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
26 myscriptname=`basename $0 .sh`
29 ps aux | grep ${myscriptname} | grep -v emacs | grep -v vim
31 numprocsp2=`ps aux | grep ${myscriptname} | grep -v emacs | grep -v vim | wc -l`
35 if [ $numprocsp2 -gt 3 ]; then
39 # get our Kerberos ticket
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
47 phost=lbnedaq@lbnegpvm01.fnal.gov
49 read tmpstring < ${scriptdir}/fstring.txt
51 for filename in `ssh ${inputremoteuser} ls ${inputremote}/lbne_r*.root | grep -v lbne_r-_sr-_`
54 # needed for ftp -- put files in the right directory
55 cd ${localincomingdir}
57 fbase=`basename $filename`
58 for itry in `seq 1 $ntrylimit`
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 " "`
66 # first attempt -- use scp to pull the file
67 # scp -q ${inputremoteuser}:${filename} $localincomingdir/
69 # second attempt -- push the file with cp using the disk mount on the gateway
70 # ssh ${inputremoteuser} cp -f ${filename} ${localincomingdir_rem}/
72 # third attempt -- use ftp
74 ftp -n $remotemachine <<EOF
76 quote PASS ${tmpstring}
85 localchecksum=`cksum $localincomingdir/$fbase`
86 checksumvalue_inputlocal=`echo $localchecksum | cut -f 1 -d " "`
87 checksumsize_inputlocal=`echo $localchecksum | cut -f 2 -d " "`
90 echo $checksumvalue_inputlocal
91 echo $checksumvalue_inputremote
92 echo $checksumsize_inputlocal
93 echo $checksumsize_inputremote
95 if [ $checksumvalue_inputlocal -eq $checksumvalue_inputremote ]
97 if [ $checksumsize_inputlocal -eq $checksumsize_inputremote ]
99 echo "Succeeded in copying $fbase"
100 mv -v $localincomingdir/$fbase $localtransdir
101 ssh $inputremoteuser mv $filename $inputtransferred
106 if [ $success -ne 1 ]
108 mv -v $localincomingdir/$fbase $localfaildir
113 $scriptdir/make_metadata35t_declare.sh $localtransdir $localfaildir $scriptdir $filelistdir
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
121 for filename in `ls *.root`
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
128 mv -v $filename $dropboxdir
132 # mv -v $filename $localdonedir
133 mv -v $filename.json $localdonedir