Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #########################
- # Last Updated: 2016-0301
- #########################
- ####################################################################
- # This was created because we had a need. If you're considering
- # using this, you have that same need. While I'm not particularly
- # good at scripting, as you can tell by how this is written, this
- # SHOULD be pretty safe to run without negatively affecting your
- # HQ/DVS, as we only read from them.
- #
- # This script DOES NOT write to them at all.
- #
- # Any modifications only occur to files that have been copied to
- # your local computer, NOT on HQ/DVS, so I think this is safe.
- #
- # Also, I wrote this for running from my Mac. Needless to say,
- # customize everything to fit your environment.
- #
- # That being said, read through this fully, and by running this,
- # you assume all risks and responsibilities associated with it.
- ####################################################################
- ####################################################################
- # These are our paths for the directories needed AFTER MOUNTING HQ.
- #
- # Customize to fit your environment.
- ####################################################################
- mailbox="/Volumes/z$/Shoreline Data/Vms/SHORETEL"
- messages="/Volumes/z$/Shoreline Data/Vms/Message"
- ####################################################################
- # If you want this to be slightly interactive, uncomment the
- # following two lines, and comment out the third.
- #
- # Otherwise, remember to pass a VALID extension as an argument.
- ####################################################################
- # echo "Enter the extension you wish to export voicemails from:"
- # read extension
- extension=${1?Extension argument missing!}
- ####################################################################
- # This checks to make sure that the extension you entered, has a
- # mailbox associated with it on HQ/DVS. If not, it will exit.
- #
- # If there is a mailbox, then it will create a directory with the
- # current date and time, followed by the extension on the Desktop.
- # Then we throw that path into a variable, so a new directory is
- # not created with each passing second the script is running.
- #
- # This is just for organization. I like having the voicemails
- # dumped into a folder on my desktop. Change as you like.
- ####################################################################
- if [[ -e "$mailbox"/$extension ]]; then
- folder=$HOME/Desktop/$(date +%Y-%m%d_%H%M%S_$extension)
- echo "Creating $folder"
- mkdir $folder
- echo "Directory created."
- else
- echo "There is no mailbox associated with that extension."
- exit 10
- fi
- ####################################################################
- # So the for loop removes the binary from the Mailbox.dat file,
- # then we awk for anything that is exactly 9 characters, which for
- # our environment is the Message ID, which we want.
- #
- # Each voicemail has two components:
- # - the WAV file: the actual audio.
- # - the MSG file: this is what you receive in Communicator,
- # informing you that you have a message. The MSG file contains
- # information about the voicemail. We are want the Caller ID.
- # You will only have either a WAV AND MSG, or only a MSG.
- #
- # So, we find all the Message IDs, then check if there is a WAV
- # with that ID. If so, tell us there is, then copy the file
- # (with -p to preserve file attributes, such as Date Modified) to
- # the directory created above. After that, inform us that renaming
- # will take place. We are renaming the file from the Message ID to
- # include the following information:
- # - Date Modified: when the message was received (YYYY-MMDD_HHMMSS)
- # - Caller ID: which we are awking from the MSG file.
- ####################################################################
- for i in $(strings "$mailbox"/$extension/Mailbox.dat | awk 'length($1) == 9 {print $1}'); do
- if [[ -e "$messages"/$i.wav ]]; then
- echo "$i.wav exists and will be copied."
- cp -p "$messages"/$i.wav $folder/$i.wav
- echo "Copying $i.wav complete."
- 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."
- 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
- echo "Renaming complete."
- else
- echo "Skipping $i, because $i.wav does not exist."
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement