No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

create_mongodb.sh 649B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #! /bin/bash
  2. usage() {
  3. echo -e "Usage : $0 host port database newuser_identifier newuser_pwd (admin_identifier|config_file) [admin_pwd]" 1>&2
  4. echo -e "config_file has to define ADMIN and ADMINPWD" 1>&2
  5. exit 1
  6. }
  7. if [ $# -lt 6 ]
  8. then
  9. echo "Not enough arguments" 1>&2
  10. usage
  11. fi
  12. if [ $# -eq 6 ]
  13. then
  14. if [ ! -f $6 ]
  15. then
  16. echo "Not enough arguments or the configation file $6 doesn't exist" 1>&2
  17. usage
  18. else
  19. . $6
  20. fi
  21. fi
  22. if [ $# -eq 7 ]
  23. then
  24. ADMIN=$6
  25. ADMINPWD=$7
  26. fi
  27. host=$1
  28. port=$2
  29. db=$3
  30. newuser=$4
  31. newuserpwd=$5
  32. mongo $1:$2/admin -u $ADMIN -p $ADMINPWD <<EOF
  33. db.addUser('$4', '$5')
  34. use $db
  35. quit()
  36. EOF