bash脚本使得连接使用freetds的,相互作用,不退出(只是挂起) [英] Bash script makes connection using FreeTDS, interacts, doesn't exit (just hangs)

查看:243
本文介绍了bash脚本使得连接使用freetds的,相互作用,不退出(只是挂起)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个脚本freetds的将记录插入到一​​个MSSQL数据库。在 USE 插入命令的工作,但退出命令不和它挂起。我试过重定向标准输出,但抱怨。我想我会用期待否则。 MEH。谢谢你。

I'm using FreeTDS in a script to insert records into a MSSQL database. TheUSEandINSERTcommands work, but theexitcommand doesn't and it hangs. I've tried redirectingstdoutbutcatcomplains. I suppose I will use Expect otherwise. Meh. Thanks.

回声-e使用DB \\非政府组织\\ n插入INTO db_table(ID,数据,元)\\ nVALUES(1,'数据','元')\\非政府组织\\ n退出>临时文件
猫临时文件 - | TSQL -H 10.10.10.10 -p 1433 -U用户-P通

推荐答案

您是不是要找这样做:猫临时文件 - ?这意味着,它会等待你preSS <大骨节病>控制 + <大骨节病> D ,因为它正试图从标准输入读为好。

Did you mean to do this: cat tempfile -? It means that it will wait for you to press Ctrl+D, because it is trying to read from standard input as well.

如果没有,删除 -

此外,作为伊格纳西奥建议,你可以把它更干净写为定界符:

Also, as Ignacio suggests, you could write it more cleanly as a heredoc:

tsql -H 10.10.10.10 -p 1433 -U user -P pass <<EOF
USE db
GO
INSERT INTO db_table (id, data, meta)
VALUES (1, 'data', 'meta')
GO
exit
EOF

或者干脆什么都不带新行,而不是 \\ n 回声:

Or just do the echo with literal newlines rather than \n:

echo "
USE db
GO
INSERT INTO db_table (id, data, meta)
VALUES (1, 'data', 'meta')
GO
exit
" > tempfile

,然后使用标准输入重定向(&LT; )运行它是这样的:

tsql -H 10.10.10.10 -p 1433 -U user -P pass < tempfile

这篇关于bash脚本使得连接使用freetds的,相互作用,不退出(只是挂起)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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