Собственно сам скрипт. В нём так же есть проверка на запуск от нужного юзера.
#!/bin/sh DB_NAME=$1 PSQL=/usr/bin/psql EGREP=/usr/bin/egrep if [ $# = 1 ] then if [ `id -nu` = 'postgres' ] then for S in `$PSQL -qAt -c "SELECT schema_name FROM information_schema.schemata;" $DB_NAME | $EGREP -v 'pg_|information_schema'` do for tbl in `$PSQL -qAt -c "SELECT table_name FROM information_schema.tables WHERE table_schema = '$S';" $DB_NAME` do $PSQL -c "ALTER TABLE ${S}.${tbl} OWNER TO deposit" $DB_NAME done done else echo "This script run ONLY from user postgres" echo "Example: su - postgres -c \"$0\"" exit 1 fi else echo "Error in usage" echo "Use: $0 DB_NAME" exit 1 fi