分页: 1 / 1

脚本中多个参数就无法执行?

发表于 : 2024-05-24 13:02
slysmart
OUT_SQL =“/home/abc/backup/”$(date +"%Y%m%d").dump
pg_dump -h localhost -U postgres -d test -F c -b -f $OUT_SQL --这句执行没问题
----------------------------------
DB_USER="postgres "
DB_NAME="test"
OUT_SQL =“/home/abc/backup/”$(date +"%Y%m%d").dump
pg_dump -h localhost -U $DB_USER -d DE_NAME -F c -b -f $OUT_SQL
执行”pg_dump: error: connection to at "localhost"“

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-24 14:27
qy117121
你下面数据库名称那里错了啊

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-24 14:41
slysmart
没有错,但就是用参数形式无法执行

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-24 14:57
slysmart
只是用户名和数据库名变成形参就无法执行了

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-24 19:03
astolia
slysmart 写了: 2024-05-24 14:41 没有错,但就是用参数形式无法执行
你再好好看看?
slysmart 写了: 2024-05-24 13:02 DB_USER="postgres "
DB_NAME="test"
OUT_SQL =“/home/abc/backup/”$(date +"%Y%m%d").dump
pg_dump -h localhost -U $DB_USER -d DE_NAME -F c -b -f $OUT_SQL
执行”pg_dump: error: connection to at "localhost"“
还有一处没法用颜色标记的地方:DB_USER赋值的时候引号里多加了一个空格
等于是你用户名和数据库名全部没有设置对就去连接了

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-25 10:27
lilydjwg
说句题外话:竟然有人专门用 localhost 连接 postgresql 数据库。
另外 postgresql 用户名不支持空格的吧?

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-28 8:35
slysmart
astolia 写了: 2024-05-24 19:03
slysmart 写了: 2024-05-24 14:41 没有错,但就是用参数形式无法执行
你再好好看看?
slysmart 写了: 2024-05-24 13:02 DB_USER="postgres "
DB_NAME="test"
OUT_SQL =“/home/abc/backup/”$(date +"%Y%m%d").dump
pg_dump -h localhost -U $DB_USER -d DE_NAME -F c -b -f $OUT_SQL
执行”pg_dump: error: connection to at "localhost"“
还有一处没法用颜色标记的地方:DB_USER赋值的时候引号里多加了一个空格
等于是你用户名和数据库名全部没有设置对就去连接了
感谢解答!
这个错误是我手误打错,实际环境中没有这个两个问题。
完整报错为:pg_dump: error: connection to server at "localhost"(127.0.01),port 5432 faile "does not exist"postgres

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-28 9:37
astolia
slysmart 写了: 2024-05-28 8:35 感谢解答!
这个错误是我手误打错,实际环境中没有这个两个问题。
完整报错为:pg_dump: error: connection to server at "localhost"(127.0.01),port 5432 faile "does not exist"postgres
你别手打了,直接把命令和结果拍照/截屏发上来

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-28 13:07
slysmart
error.jpg
error.jpg (8.51 KiB) 查看 5963 次
,错误见截图
shell.jpg
,shell脚本

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-28 14:31
astolia
检查一下这段脚本的换行是不是dos/win风格,即回车符+换行符。
如果是的话,去掉回车符将其转换成unix风格。可以用dos2unix,或者用sed -i 's/\r//' xxx.sh

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-28 16:02
slysmart
astolia 写了: 2024-05-28 14:31 检查一下这段脚本的换行是不是dos/win风格,即回车符+换行符。
如果是的话,去掉回车符将其转换成unix风格。可以用dos2unix,或者用sed -i 's/\r//' xxx.sh
非常感谢,就是此问题导致的了。

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-28 16:28
slysmart
lilydjwg 写了: 2024-05-25 10:27 说句题外话:竟然有人专门用 localhost 连接 postgresql 数据库。
另外 postgresql 用户名不支持空格的吧?
刚开始使用postgresql,实际应用中为IP地址
host all all 192.168.1.0/24 md5 方式
这样安全性够不够?

Re: 脚本中多个参数就无法执行?

发表于 : 2024-05-28 17:22
astolia
slysmart 写了: 2024-05-28 16:28 刚开始使用postgresql,实际应用中为IP地址
host all all 192.168.1.0/24 md5 方式
这样安全性够不够?
看你的软件架构了。如果是直接开放数据库给远端连,建议将连接方式换成hostssl,认证方式换成scram-sha-256。如果是只供本机上服务端程序访问,连接方式换成local