bash脚本使得连接使用freetds的,相互作用,不退出(只是挂起) [英] Bash script makes connection using FreeTDS, interacts, doesn't exit (just hangs)
问题描述
我用一个脚本freetds的将记录插入到一个MSSQL数据库。在 USE
和插入
命令的工作,但退出
命令不和它挂起。我试过重定向标准输出
,但猫
抱怨。我想我会用期待否则。 MEH。谢谢你。
I'm using FreeTDS in a script to insert records into a MSSQL database. TheUSE
andINSERT
commands work, but theexit
command doesn't and it hangs. I've tried redirectingstdout
butcat
complains. 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屋!