脚本编写psql问题 [英] scripting & psql issues

查看:70
本文介绍了脚本编写psql问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计,

可能这是你已经听过很多次的问题

但是我无法找到解决方案。


我正在使用shell脚本为我创建一个文本文件。

看起来好像

#!/ usr / local / bin / bash

psql -c" select bar from bar;" -d database1 -t

psql -c" \ q" -d database1

退出0


第二个psql -c" \ q"命令用于从第一个数据库中注销

。但我不确定这是否是正确的b $ b。我如何混合这些sql和psql元命令

否则,如果我想能够使用myscript>

output.txt来获取此选择的输出<文件output.txt中的
语句。我打算给b
写一个cron工作。


另一个问题是密码。通常当我登录到
database1时,我必须发出密码,因为pg_hba.conf文件中只有

超级用户可信。但是对于我希望能够在

背景中运行的脚本,我需要添加一个条目



pg_hba.conf文件也信任该用户。但是从

安全的角度来看,我想知道这是否是实现它的最佳方式。


提前致谢


__________________________________

你是Yahoo!?

Yahoo!邮件是新的和改进的 - 检查出来!
http://promotions.yahoo。 com / new_mail


---------------------------(播出结束)---------------------------

提示6:您是否搜索了我们的列表档案?

http://archives.postgresql.org

推荐答案



于18/08/2004 12:57 Dino Vliet写道:

On 18/08/2004 12:57 Dino Vliet wrote:
嗨大家好,
可能这是你已经听过很多次的问题
但是我无法找到它的解决方案。

我正在使用一个shell脚本为我创建一个文本文件。
它看起来像
#!/ usr / local / bin / bash
psql -c" select foo from bar;" -d database1 -t
psql -c" \ q" -d database1
退出0

第二个psql -c" \ q"命令用于从第一个数据库注销。但我不确定这是否正确。


不需要。第一个命令将自行退出(man psql)。

如何混合使用这些sql和psql元命令
如果我想能够使用myscript>
output.txt从文件output.txt中获取此select
语句的输出。我打算为它写一份cron工作。


您可以使用
Hi folks,
probably this is a question you''ve heard so many times
but I wasn''t able to find a solution to it.

I''m using a shell script to create a textfile for me.
It looks like
#!/usr/local/bin/bash
psql -c "select foo from bar;" -d database1 -t
psql -c "\q" -d database1
exit 0

The second psql -c "\q" command is used to logout from
the first database. But I''m not sure whether this is
correct.
Not needed. The 1st command will exit by itself (man psql).
How do I mix these sql and psql meta-commands
otherwise if I want to be able to use myscript >
output.txt to get the output from this select
statement in the file output.txt. I''m planning to
write a cron job for it too.
You could use


HOME / .psqlrc。

另一个问题是密码。通常当我登录数据库1时,我必须发出密码,因为只有
超级用户在pg_hba.conf文件中受信任。但是对于我希望能够在这样的背景中运行的脚本,我必须在
pg_hba.conf文件中添加一个条目来信任该用户。但是从安全的角度来看,我想知道这是否是实现它的最佳途径。
HOME/.psqlrc.

Another issues is passwords. Normally when I log onto
database1, I have to issue a password because only the
superuser is trusted in the pg_hba.conf file. However
for scripts that I want to be able to run in the
background like this one, I had to add an entry to the
pg_hba.conf file to trust this user also. But as from
security point of view, I''m wondering if this is the
best way to achieve it.




你可以使用



You could use


HOME / .pgpass。


-

Paul Thomas

+ - ----------------------------- + -------------------- ------------------------- +

| Thomas Micro Systems Limited |软件解决方案

商业|

|计算机顾问|
http://www.thomas-micro -systems-ltd.co.uk |

+ ---------------------------- - + + ---------------------------------------------


---------------------------(广播结束)------- --------------------

提示5:您检查了我们广泛的常见问题解答吗?

http://www.postgresql.org/docs/faqs/FAQ.html

HOME/.pgpass.

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for
Business |
| Computer Consultants |
http://www.thomas-micro-systems-ltd.co.uk |
+------------------------------+---------------------------------------------+

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html


这篇关于脚本编写psql问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆