script.sh
#!/bin/bash if ["$(whoami)" != "root"]; then echo "Start script as root root!" exit 1 fi _DBNAME="$1" while [ -z "$_DBNAME" ]; do echo "Write DB name!" read _DBNAME done _DBUSER="$2" while [ -z "$_DBUSER" ]; do echo "Write DB username!" read _DBUSER done _PATH="$3" while [ -z "$_PATH" ]; do echo "Write path to DB dump file!" read _PATH done service postgresql restart su - postgres -c "dropdb $_DBNAME" su - postgres -c "createdb $_DBNAME -O $_DBUSER" su - postgres -c "psql $_DBNAME < $_PATH"