推荐答案 于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.htmlHOME/.pgpass.--Paul Thomas+------------------------------+---------------------------------------------+| Thomas Micro Systems Limited | Software Solutions forBusiness || 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问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!