Advertisement
cui_amoreno

export_Shoretel_VoiceMail.sh

Feb 29th, 2016
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.37 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #########################
  4. # Last Updated: 2016-0301
  5. #########################
  6.  
  7. ####################################################################
  8. # This was created because we had a need. If you're considering
  9. # using this, you have that same need. While I'm not particularly
  10. # good at scripting, as you can tell by how this is written, this
  11. # SHOULD be pretty safe to run without negatively affecting your
  12. # HQ/DVS, as we only read from them.
  13. #
  14. # This script DOES NOT write to them at all.
  15. #
  16. # Any modifications only occur to files that have been copied to
  17. # your local computer, NOT on HQ/DVS, so I think this is safe.
  18. #
  19. # Also, I wrote this for running from my Mac. Needless to say,
  20. # customize everything to fit your environment.
  21. #
  22. # That being said, read through this fully, and by running this,
  23. # you assume all risks and responsibilities associated with it.
  24. ####################################################################
  25.  
  26. ####################################################################
  27. # These are our paths for the directories needed AFTER MOUNTING HQ.
  28. #
  29. # Customize to fit your environment.
  30. ####################################################################
  31.  
  32. mailbox="/Volumes/z$/Shoreline Data/Vms/SHORETEL"
  33. messages="/Volumes/z$/Shoreline Data/Vms/Message"
  34.  
  35. ####################################################################
  36. # If you want this to be slightly interactive, uncomment the
  37. # following two lines, and comment out the third.
  38. #
  39. # Otherwise, remember to pass a VALID extension as an argument.
  40. ####################################################################
  41.  
  42. # echo "Enter the extension you wish to export voicemails from:"
  43. # read extension
  44. extension=${1?Extension argument missing!}
  45.  
  46. ####################################################################
  47. # This checks to make sure that the extension you entered, has a
  48. # mailbox associated with it on HQ/DVS. If not, it will exit.
  49. #
  50. # If there is a mailbox, then it will create a directory with the
  51. # current date and time, followed by the extension on the Desktop.
  52. # Then we throw that path into a variable, so a new directory is
  53. # not created with each passing second the script is running.
  54. #
  55. # This is just for organization. I like having the voicemails
  56. # dumped into a folder on my desktop. Change as you like.
  57. ####################################################################
  58.  
  59. if [[ -e "$mailbox"/$extension ]]; then
  60. folder=$HOME/Desktop/$(date +%Y-%m%d_%H%M%S_$extension)
  61. echo "Creating $folder"
  62. mkdir $folder
  63. echo "Directory created."
  64. else
  65. echo "There is no mailbox associated with that extension."
  66. exit 10
  67. fi
  68.  
  69. ####################################################################
  70. # So the for loop removes the binary from the Mailbox.dat file,
  71. # then we awk for anything that is exactly 9 characters, which for
  72. # our environment is the Message ID, which we want.
  73. #
  74. # Each voicemail has two components:
  75. # - the WAV file: the actual audio.
  76. # - the MSG file: this is what you receive in Communicator,
  77. # informing you that you have a message. The MSG file contains
  78. # information about the voicemail. We are want the Caller ID.
  79. # You will only have either a WAV AND MSG, or only a MSG.
  80. #
  81. # So, we find all the Message IDs, then check if there is a WAV
  82. # with that ID. If so, tell us there is, then copy the file
  83. # (with -p to preserve file attributes, such as Date Modified) to
  84. # the directory created above. After that, inform us that renaming
  85. # will take place. We are renaming the file from the Message ID to
  86. # include the following information:
  87. # - Date Modified: when the message was received (YYYY-MMDD_HHMMSS)
  88. # - Caller ID: which we are awking from the MSG file.
  89. ####################################################################
  90.  
  91.  
  92. for i in $(strings "$mailbox"/$extension/Mailbox.dat | awk 'length($1) == 9 {print $1}'); do
  93. if [[ -e "$messages"/$i.wav ]]; then
  94. echo "$i.wav exists and will be copied."
  95. cp -p "$messages"/$i.wav $folder/$i.wav
  96. echo "Copying $i.wav complete."
  97. echo "Renaming $i.wav to $(stat -f %Sm -t %Y-%m%d_%H%M%S $folder/$i.wav)_$(strings "$messages"/$i.msg | awk 'FNR==4{print $0}').wav."
  98. mv $folder/$i.wav $folder/$(stat -f %Sm -t %Y-%m%d_%H%M%S $folder/$i.wav)_$(strings "$messages"/$i.msg | awk 'FNR==4{print $0}').wav
  99. echo "Renaming complete."
  100. else
  101. echo "Skipping $i, because $i.wav does not exist."
  102. fi
  103. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement