Guest User

Untitled

a guest
Feb 7th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Author: Thyrus Gorges
  4. # Date: 2015/03/04
  5.  
  6. #The MIT License (MIT)
  7.  
  8. #Copyright (c) <2015> <Thyrus Gorges>
  9.  
  10. #Permission is hereby granted, free of charge, to any person obtaining a copy
  11. #of this software and associated documentation files (the "Software"), to deal
  12. #in the Software without restriction, including without limitation the rights
  13. #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  14. #copies of the Software, and to permit persons to whom the Software is
  15. #furnished to do so, subject to the following conditions:
  16.  
  17. #The above copyright notice and this permission notice shall be included in
  18. #all copies or substantial portions of the Software.
  19.  
  20. #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  23. #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  24. #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  25. #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  26. #THE SOFTWARE.
  27.  
  28.  
  29. # Build a Polycom Directory XML file
  30. # by pulling the usernames and extensions of all SIP users
  31.  
  32. # Set so we can loop on newlines instead of spaces
  33. IFS=$'\n'
  34.  
  35. # MySQL Creds
  36. SQLUSER=<replace-user>
  37. SQLPASS=<replace-password>
  38.  
  39. # Declare our file
  40. FILE=/tftpboot/000000000000-directory.xml
  41.  
  42. # Remove old file
  43. rm $FILE
  44.  
  45. # ReCreate our file
  46. touch $FILE
  47.  
  48.  
  49. # Write the header of the file
  50. # Passing the -e option to echo allows us to use tabs
  51. echo -e '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' >> $FILE
  52. echo -e '<!-- $RCSfile: 000000000000-directory~.xml,v $ $Revision: 1.3 $ -->' >> $FILE
  53. echo -e '<directory>' >> $FILE
  54. echo -e "\t<item_list>" >> $FILE
  55.  
  56.  
  57. # Query Database
  58. # We pass -N to MySQL so it doens't print headers
  59. for i in $( mysql -u $SQLUSER -p$SQLPASS -N -e "use asterisk; select extension, name from users;" ); do
  60. # Assign Variables to each field
  61. EXTEN=`echo $i | cut -f1`
  62. FN=`echo $i | cut -f2 | cut -d" " -f1`
  63. LN=`echo $i | cut -d" " -f2`
  64. # The item tag is the beginning of a contact
  65. echo -e "\t\t<item>" >> $FILE
  66. echo -e "\t\t\t<ln> $LN </ln>" >> $FILE
  67. echo -e "\t\t\t<fn> $FN </fn>" >> $FILE
  68. echo -e "\t\t\t<ct> $EXTEN </ct>" >> $FILE
  69. echo -e "\t\t</item>" >> $FILE
  70. done
  71.  
  72. # Write file endings
  73. echo -e "\t</item_list>" >> $FILE
  74. echo -e "</directory>" >> $FILE
Add Comment
Please, Sign In to add comment