Guest User

Untitled

a guest
Mar 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #!/bin/sh
  2. ################
  3. ##AwipsToLan.sh##
  4. ################
  5. #Brad Schick WFO Goodland, KS
  6. #11/10/2016
  7. ##Script used to rsync files via cron from /localapps/runtime/AwipsToLan/data to Linux VM outside of awips.
  8. ##Version 1.3
  9.  
  10. #############################
  11. #Configuration Variables
  12. SID=GLD
  13. path=/localapps/runtime/AwipsToLan
  14. ldadstagearea=/data/ldad/public/AwipsToLan/
  15. kvmHOST2rsync=gld-ls-kvm-intra
  16. kvmHOSTrsyncModule=AwipsToLan
  17. #End of Config Variables
  18. #############################
  19.  
  20. ##Log when this was ran the last time
  21. echo "Script launched by `whoami` on `date`">$path/log/AwipsToLan.log
  22.  
  23. ##Check for a active lock file, if present we do not continue
  24. if [[ -a $path/tmp/.lock ]]; then
  25. echo "Lock File Present! This means AwipsToLan.sh is still running, now EXITING... $path/tmp/.lock" >>$path/log/AwipsToLan.log
  26. exit
  27. fi
  28.  
  29. ##Run a quick check and see if we have data to move, if not we exit gracefully.
  30. if [ "$(ls $path/data)" ]; then
  31. echo "We have files to rsync, so lets get to it!">>$path/log/AwipsToLan.log
  32.  
  33. ##Create a lock file to keep another instance of this from stepping itself
  34. echo "Creating a $path/tmp/.lock to keep another instance of this script from stepping on itself">>$path/log/AwipsToLan.log
  35. touch $path/tmp/.lock
  36.  
  37. ##Grab a listing of the files we are going to rsync
  38. files2rsync=`ls $path/data`
  39. echo "The following files/directories will be rsync'd this session">>$path/log/AwipsToLan.log
  40.  
  41. ##SCP any data to LDAD
  42. scp -qr $path/data/* ldad@ls:$ldadstagearea
  43.  
  44. ##Remove the files from this location since they have been moved over to LDAD
  45. for x in $files2rsync
  46. do
  47. echo "Files rsync'd to ldad, so now deleting $path/data/$x">>$path/log/AwipsToLan.log
  48. rm -rf $path/data/$x
  49. done
  50.  
  51. #ssh to ldad and run the rsync to the VM
  52. ssh -q ldad@ls rsync -poqrtzv --force --progress --stats --remove-source-files $ldadstagearea $kvmHOST2rsync::$kvmHOSTrsyncModule
  53.  
  54. echo "Rsync complete" >>$path/log/AwipsToLan.log
  55.  
  56. ##Remove the Lock File
  57. rm -rf $path/tmp/.lock
  58.  
  59. echo "Lock File removed... now exiting.">>$path/log/AwipsToLan.log
  60. else
  61. echo "No new files found, so exiting...">>$path/log/AwipsToLan.log
  62. fi
  63.  
  64. ##Exit, that's all folks!
  65. exit
Add Comment
Please, Sign In to add comment