Advertisement
Guest User

Untitled

a guest
Mar 15th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. # Usage: storeftpputall machine
  2. set -x
  3. MACHINE=$1 # name of remote machine
  4. USERNAME='ftpstore'
  5. PASS='ftppassword'
  6. PUBDIR='/u/ftpstore' # Transfer directory tree
  7. INDIR='transfer/in' # Remote system, where files go in
  8. MYNOWPID=$$ # Proc ID of this process.
  9.  
  10. # Make sure no other storeftpputs are running to that store,
  11. # else you could get an attempted overwrite, or at least overload
  12. # the modem line. Use PID lock files.
  13.  
  14. # Check for PID file locking ftp to remote store
  15. if [ -f /usr/tmp/$MACHINE.put.* ]
  16. then
  17. STORELOKPID1=''
  18. STORELOKPID1=`ls /usr/tmp/$MACHINE.put.* | sed -e "s|$MACHINE.put.||g"`
  19. for j in $STORELOKPID1
  20. do
  21. k=`basename $j`
  22. LIVEPID=`ps -ef | grep $k | grep -v 'grep'`
  23. if [ -n "$LIVEPID" ]
  24. then
  25. echo 'Storeftpput script already in progress. Please wait'
  26. sleep 2
  27. else
  28. echo "Removing stale lockfile $MACHINE.$k"
  29. rm "/usr/tmp/$MACHINE.put.$k" # Remove stale lock file
  30. sleep 2
  31. fi
  32. done
  33. fi
  34.  
  35. # Any stale locks should be gone. Wait for any live
  36. # storeftpput scripts to finish and remove their own lockfiles,
  37. # then proceed.
  38. while [ -f /usr/tmp/$MACHINE.put.* ]
  39. do
  40. echo 'Storeftpput script already in progress. Please wait.'
  41. echo "Retrying at 45 second intervals."
  42. sleep 45
  43. done
  44.  
  45. # Assert own lockfile on line
  46. touch /usr/tmp/$MACHINE.put.$MYNOWPID
  47. chmod 664 /usr/tmp/$MACHINE.put.$MYNOWPID
  48.  
  49. # Check for outbound store files. If found, send them.
  50. cd $PUBDIR/out/$MACHINE
  51. if [ -f *.tar.Z ]
  52. then
  53.  
  54. NUMBER=`ls *.tar.Z|sed -e "s|.tar.Z||g"` # Get tar file numbers
  55. for j in $NUMBER # May be more than one
  56. do
  57. ftp -i -n -v $MACHINE <<-EndFTP
  58. user $USERNAME $PASS
  59. cd $INDIR
  60. lcd $PUBDIR/out/$MACHINE
  61. binary
  62. hash
  63. put $j.tar.Z
  64. chmod 666 $j.tar.Z
  65. close
  66. EndFTP
  67. rm $j.tar.Z
  68. done
  69. fi
  70.  
  71. # Remove storeftpput lockfile
  72. rm /usr/tmp/$MACHINE.put.$MYNOWPID
  73.  
  74. echo "Done..."
  75. sleep 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement