From 7bab2a0e49e012ee93188616fe1c52fd47be3466 Mon Sep 17 00:00:00 2001 From: lqs <441785369@qq.com> Date: Wed, 19 Mar 2025 12:32:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=201.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/1.sh b/1.sh index e69de29..1fe7a35 100644 --- a/1.sh +++ b/1.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# 检查是否提供了用户名和密码 +if [ $# -ne 2 ]; then + echo "用法: $0 <用户名> <密码>" + exit 1 +fi + +# 获取用户名和密码 +username=$1 +password=$2 + +# 执行创建用户的 SQL 命令 +sudo -u postgres psql -c "CREATE USER $username WITH PASSWORD '$password';" + +# 检查命令是否执行成功 +if [ $? -eq 0 ]; then + echo "用户 $username 创建成功。" +else + echo "用户 $username 创建失败。" +fi + \ No newline at end of file