destroydb.sh
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:2k
源码类别:

数据库系统

开发平台:

Unix_Linux

  1. #!/bin/sh
  2. #-------------------------------------------------------------------------
  3. #
  4. # destroydb.sh--
  5. #    destroy a postgres database
  6. #
  7. #    this program runs the monitor with the ? option to destroy
  8. #    the requested database.
  9. #
  10. # Copyright (c) 1994, Regents of the University of California
  11. #
  12. #
  13. # IDENTIFICATION
  14. #    $Header: /usr/local/cvsroot/pgsql/src/bin/destroydb/destroydb.sh,v 1.8 1997/06/02 02:53:00 scrappy Exp $
  15. #
  16. #-------------------------------------------------------------------------
  17. CMDNAME=`basename $0`
  18. if [ -z "$USER" ]; then
  19.     if [ -z "$LOGNAME" ]; then
  20. if [ -z "`whoami`" ]; then
  21.     echo "$CMDNAME: cannot determine user name"
  22.     exit 1
  23. fi
  24.     else
  25. USER=$LOGNAME
  26. export USER
  27.     fi
  28. fi
  29. dbname=$USER
  30. forcedel=t
  31. while [ -n "$1" ]
  32. do
  33. case $1 in 
  34.         -i) forcedel=f;;
  35. -a) AUTHSYS=$2; shift;;
  36. -h) PGHOST=$2; shift;;
  37. -p) PGPORT=$2; shift;;
  38.  *) dbname=$1;;
  39. esac
  40. shift;
  41. done
  42. if [ -z "$AUTHSYS" ]; then
  43.   AUTHOPT=""
  44. else
  45.   AUTHOPT="-a $AUTHSYS"
  46. fi
  47. if [ -z "$PGHOST" ]; then
  48.   PGHOSTOPT=""
  49. else
  50.   PGHOSTOPT="-h $PGHOST"
  51. fi
  52. if [ -z "$PGPORT" ]; then
  53.   PGPORTOPT=""
  54. else
  55.   PGPORTOPT="-p $PGPORT"
  56. fi
  57. answer=y
  58. if [ "$forcedel" = f ]
  59.    then
  60.    answer=f
  61.    while [ "$answer" != y -a "$answer" != n ]
  62.    do
  63.        echo "Database '$dbname' will be permanently deleted."
  64.        echo -n "Are you sure? (y/n) "
  65.        read answer
  66.    done
  67. fi
  68. if [ "$answer" = y ]
  69. then
  70.   psql -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "drop database $dbname" template1
  71.     if [ $? -ne 0 ]
  72.        then echo "$CMDNAME: database destroy failed on $dbname."
  73.        exit 1
  74.     fi
  75. fi
  76. exit 0