Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Usage: storeftpputall machine
- set -x
- MACHINE=$1 # name of remote machine
- USERNAME='ftpstore'
- PASS='ftppassword'
- PUBDIR='/u/ftpstore' # Transfer directory tree
- INDIR='transfer/in' # Remote system, where files go in
- MYNOWPID=$$ # Proc ID of this process.
- # Make sure no other storeftpputs are running to that store,
- # else you could get an attempted overwrite, or at least overload
- # the modem line. Use PID lock files.
- # Check for PID file locking ftp to remote store
- if [ -f /usr/tmp/$MACHINE.put.* ]
- then
- STORELOKPID1=''
- STORELOKPID1=`ls /usr/tmp/$MACHINE.put.* | sed -e "s|$MACHINE.put.||g"`
- for j in $STORELOKPID1
- do
- k=`basename $j`
- LIVEPID=`ps -ef | grep $k | grep -v 'grep'`
- if [ -n "$LIVEPID" ]
- then
- echo 'Storeftpput script already in progress. Please wait'
- sleep 2
- else
- echo "Removing stale lockfile $MACHINE.$k"
- rm "/usr/tmp/$MACHINE.put.$k" # Remove stale lock file
- sleep 2
- fi
- done
- fi
- # Any stale locks should be gone. Wait for any live
- # storeftpput scripts to finish and remove their own lockfiles,
- # then proceed.
- while [ -f /usr/tmp/$MACHINE.put.* ]
- do
- echo 'Storeftpput script already in progress. Please wait.'
- echo "Retrying at 45 second intervals."
- sleep 45
- done
- # Assert own lockfile on line
- touch /usr/tmp/$MACHINE.put.$MYNOWPID
- chmod 664 /usr/tmp/$MACHINE.put.$MYNOWPID
- # Check for outbound store files. If found, send them.
- cd $PUBDIR/out/$MACHINE
- if [ -f *.tar.Z ]
- then
- NUMBER=`ls *.tar.Z|sed -e "s|.tar.Z||g"` # Get tar file numbers
- for j in $NUMBER # May be more than one
- do
- ftp -i -n -v $MACHINE <<-EndFTP
- user $USERNAME $PASS
- cd $INDIR
- lcd $PUBDIR/out/$MACHINE
- binary
- hash
- put $j.tar.Z
- chmod 666 $j.tar.Z
- close
- EndFTP
- rm $j.tar.Z
- done
- fi
- # Remove storeftpput lockfile
- rm /usr/tmp/$MACHINE.put.$MYNOWPID
- echo "Done..."
- sleep 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement