在 UNIX 机器中执行 bcp 时出现错误

发布于 2025-01-03 05:35:27 字数 614 浏览 3 评论 0原文

目前我正在 Unix 机器上执行 Perl 脚本。 Perl 脚本内部使用 BCP 命令从 MS-SQL DB 获取数据。相同的 perl 脚本在 Windows 中正确运行。但是当我在 Unix 中执行它时(使用 Putty)。它在控制台上显示以下错误消息。

sh: bcp: command not found

下面是我在 perl 脚本中的 sql 命令。

"bcp \"select drive_id, ilf, xcoord, ycoord 
from $mdtdb\.dbo\.$mdtcentraldtdtable a where 
drive_id = $driveid and not exists 
(select 'x' from $mdtdb\.dbo\.$mdtcentralaudittable b where 
a.drive_id = b.drive_id and a.ilf = b.ilf)\"
 queryout $tempdatafile -o $bcpoutfile -S $mdtsvr -q -c -t , 
 -U $user1 -P $pw1";

我能够成功连接数据库。

我需要您的帮助来解决上述 bcp 问题。

Currently I am working on executing Perl script in Unix box. The Perl script internally uses BCP command for for fetching the data from MS-SQL DB. The same perl script is properly running in Windows. But when I am executing it into Unix (using Putty). It is showing following error message on console.

sh: bcp: command not found

Below is my sql command in perl script.

"bcp \"select drive_id, ilf, xcoord, ycoord 
from $mdtdb\.dbo\.$mdtcentraldtdtable a where 
drive_id = $driveid and not exists 
(select 'x' from $mdtdb\.dbo\.$mdtcentralaudittable b where 
a.drive_id = b.drive_id and a.ilf = b.ilf)\"
 queryout $tempdatafile -o $bcpoutfile -S $mdtsvr -q -c -t , 
 -U $user1 -P $pw1";

I am successfully able to connect with the DB.

I need your help to resolve above bcp issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

£噩梦荏苒 2025-01-10 05:35:27

在unix上,有一个用于sybase客户端的bcp工具。它仅适用于 Sybase 产品。

有一个与 MSSQL 服务器一起使用的 bcp 的开源替代品: freebcp 但是 freetds库的配置有点困难,并且(这是志愿者的逆向工程工作)它仅适用于相对简单的数据类型。

要在基于 ubuntu/debian 的 Linux 机器上安装它,请运行此命令

apt-cache 搜索 freetds

freetds-common - configuration files for FreeTDS SQL client libraries
freetds-dev - MS SQL and Sybase client library (static libs and headers)
libct4 - libraries for connecting to MS SQL and Sybase SQL servers
libdbd-freetds - Freetds database server driver for libdbi
libsybdb5 - libraries for connecting to MS SQL and Sybase SQL servers
tdsodbc - ODBC driver for connecting to MS SQL and Sybase SQL servers
freetds-bin - FreeTDS command-line utilities
libaprutil1-dbd-freetds - Apache Portable Runtime Utility Library - FreeTDS Driver
sqsh - commandline SQL client for MS SQL and Sybase servers
libqt4-sql-tds - Qt 4 FreeTDS database driver

该命令是可选的:

apt-file 列表 freetds-bin

freetds-bin: /usr/bin/bsqldb
freetds-bin: /usr/bin/bsqlodbc
freetds-bin: /usr/bin/datacopy
freetds-bin: /usr/bin/defncopy
freetds-bin: /usr/bin/fisql
freetds-bin: /usr/bin/freebcp
freetds-bin: /usr/bin/osql
freetds-bin: /usr/bin/tdspool
freetds-bin: /usr/bin/tsql

这些命令安装您需要的大部分内容

apt-get install freetds-bin 
apt-get install freetds-dev 

然后您必须将连接数据输入到配置文件中

/etc/freetds/freetds.conf

[OurMSSQLServer]

    host = 1xx.xxx.xxx.xx
    port = 1433
    tds version = 8.0

也许此配置文件中的其他内容必须更改。这个我现在不记得了。

从现在开始,你就只能靠自己了。请阅读 freetds 文档: http://www.freetds.org/userguide/

freetds 软件是最新的(积极开发的)。但我认为开发团队很小。

您还可以从源代码编译 freetds,但这可能需要更多的努力。

On unix, there is a bcp tool for sybase clients. It works only for Sybase Products.

There is an open-source replacement for bcp that works with MSSQL server: freebcp But the freetds library is a bit difficult to configure, and (being a reverse engineering effort by volunteers) it works only with relatively simple datatypes.

To install it on ubuntu/debian based linux machines, run this

apt-cache search freetds

freetds-common - configuration files for FreeTDS SQL client libraries
freetds-dev - MS SQL and Sybase client library (static libs and headers)
libct4 - libraries for connecting to MS SQL and Sybase SQL servers
libdbd-freetds - Freetds database server driver for libdbi
libsybdb5 - libraries for connecting to MS SQL and Sybase SQL servers
tdsodbc - ODBC driver for connecting to MS SQL and Sybase SQL servers
freetds-bin - FreeTDS command-line utilities
libaprutil1-dbd-freetds - Apache Portable Runtime Utility Library - FreeTDS Driver
sqsh - commandline SQL client for MS SQL and Sybase servers
libqt4-sql-tds - Qt 4 FreeTDS database driver

This command is optional:

apt-file list freetds-bin

freetds-bin: /usr/bin/bsqldb
freetds-bin: /usr/bin/bsqlodbc
freetds-bin: /usr/bin/datacopy
freetds-bin: /usr/bin/defncopy
freetds-bin: /usr/bin/fisql
freetds-bin: /usr/bin/freebcp
freetds-bin: /usr/bin/osql
freetds-bin: /usr/bin/tdspool
freetds-bin: /usr/bin/tsql

These commands install most of what you need

apt-get install freetds-bin 
apt-get install freetds-dev 

You must then enter your connection data into configfile

/etc/freetds/freetds.conf

[OurMSSQLServer]

    host = 1xx.xxx.xxx.xx
    port = 1433
    tds version = 8.0

Maybe something else in this configfile has to be changed. This I don't remember right now.

From here on you are on your own. Please read the freetds docs: http://www.freetds.org/userguide/

The freetds software is up-to-date (actively developed). But the dev team is very small I think.

You can also compile freetds from source, but that may take more effort.

单挑你×的.吻 2025-01-10 05:35:27

错误非常明显:在您的 $PATH 中找不到 bcp 命令,因此它失败,但真正的问题是 bcp 是一个 MS SQL Server 实用程序,您在 UNIX 上找不到它

The error is very clear: the bcp command is not found in your $PATH and therefore it fails, but the real issue is that bcp is a MS SQL server utility and you won't find it on UNIX

失眠症患者 2025-01-10 05:35:27

You might be able to get programmatic access to an MSSQL database from Perl on unix by using DBI ‌→ DBD::ODBC ‌→ Easysoft SQL Server ODBC Driver

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文