2014-01-07 116 views
0

我做了一个脚本来连接到我的sql服务器。当我将我的脚本复制到我的终端时,它工作正常。使用tsql的Linux脚本

我连接到我的SQL Server使用T-SQL

一个树莓派,但是当我把我的脚本到一个文件来运行它的自动我得到一个错误。

首先我的脚本:

tsql -H Server -U Username -P Password 
Go 
Use master 

其粘贴到我的壳

[email protected]:~# tsql -H Server -U Username -P Password 
Missing argument -p, looking for default instance ... found default instance, port 1433 
locale is "nl_NL" 
locale charset is "ISO-8859-1" 
using default charset "ISO-8859-1" 
1> GO 
1> use master 
2> go 
1> 

我把完全相同的脚本到文件data.sh 但它不会工作。

[email protected]:~# ./data.sh 
Missing argument -p, looking for default instance ... found default instance, port 1433 
locale is "nl_NL" 
locale charset is "ISO-8859-1" 
using default charset "ISO-8859-1" 
1> 

谁能帮我解决这个问题

感谢

回答

2

this answer。要使data.sh脚本正常工作,您需要将SQL语句传递到tsql程序中。如上所述,tsql程序没有输入,所以它只是打印提示。

试试这个在data.sh:

tsql -H Server -U Username -P Password <<EOF 
    GO 
    use master 
    GO 
EOF 
+0

感谢您的回复 不幸的是它不会工作 它看起来像他使用的命令,但没有任何结果或输出 根@树莓派:〜#./databasecopy.sh 缺少参数-p,寻找默认实例...找到默认实例,端口1433 区域设置为“nl_NL” 区域设置字符集为“ISO-8859-1” 使用默认字符集“ISO-8859-1” 1> 1> 2> 1>根@raspberrypi:〜# – GS1

+0

“Go”和“use master”命令没有结果或输出,因此注释中的输出与粘贴到shell的第一个示例中的输出相匹配。尝试放置一个在脚本中产生结果的SQL SELECT语句,看看是否可行。 –

+0

对不起,我忘记说,因为它不会给我输出的原因,我改变了脚本添加一个创建数据库。 但没有数据库创建 – GS1

0

您可能正在使用命名管道。尝试加入-L [instance_name]