473,915 Members | 5,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xp_cmdshell and BLAT

Would like to implement Blat on SQL Server 2000. I'm looking for
example syntax for setting up BLAT with xp_cmdshell.
TIA
Jul 20 '05 #1
3 7676
yv***********@u c.edu (Yvonne) wrote in message news:<89******* *************** ****@posting.go ogle.com>...
Would like to implement Blat on SQL Server 2000. I'm looking for
example syntax for setting up BLAT with xp_cmdshell.
TIA


I'm not familiar with blat, but have a look at example E in the Books
Online entry for xp_cmdshell - it shows how to use a SQL variable in a
call to xp_cmdshell. You simply need to build a valid command string
and execute it:

set @xp = 'blat -p ' + @parameter + ' -v ' + @value + ...
exec master..xp_cmds hell @xp

As an alternative, you might consider xp_smtp_sendmai l, which is an
extended stored procedure so can be called directly from TSQL with no
need to use a command shell:

http://sqldev.net/xp.htm

Simon
Jul 20 '05 #2

"Yvonne" <yv***********@ uc.edu> wrote in message
news:89******** *************** ***@posting.goo gle.com...
Would like to implement Blat on SQL Server 2000. I'm looking for
example syntax for setting up BLAT with xp_cmdshell.
TIA

xp_cmdshell 'd:\blat\blat d:\blat\message s\tapefail.txt -s "DB FOO has a
tap failure" -t fo*@bar.com'
Jul 20 '05 #3
yv***********@u c.edu (Yvonne) wrote in message news:<89******* *************** ****@posting.go ogle.com>...
Would like to implement Blat on SQL Server 2000. I'm looking for
example syntax for setting up BLAT with xp_cmdshell.
TIA


I am doing the same thing here.
This is the source code of my stored proc. Perhaps you will find it
usefull.

Here is how you would use it in your scripts:
EXEC SP_BLAT 's******@somewh ere.com','Daily Batch Process Failed'

or

EXEC SP_BLAT 's******@somewh ere.com','Greet ings','I wanted to say
Hello','C*@some where.com','\\F ile-Server\Shared-Data\Blat\SomeF ile.txt'

CREATE PROCEDURE SP_BLAT

@TOEMAIL VARCHAR(8000)
,@SUBJECT VARCHAR(1000)
,@BODY VARCHAR(8000) = NULL --Optional Parameter
,@CCEMAIL VARCHAR(8000) = NULL --Optional Parameter
,@ATTACHMENT VARCHAR(1000) = NULL --Optional Parameter
,@BCCEMAIL VARCHAR(8000) = NULL --Optional Parameter

AS
DECLARE @COMMANDSTRING VARCHAR(1000)
DECLARE @ATTACHTEXT BIT

SET @ATTACHTEXT = 0

--*************** *************** *************** *************** *************** **
--*** BEGIN DELETE EXISTING FILES
--*************** *************** *************** *************** *************** **
EXEC MASTER..XP_CMDS HELL 'IF EXIST
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd del
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd'
EXEC MASTER..XP_CMDS HELL 'IF EXIST
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedureMessa ge.txt
del \\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedureMessa ge.txt'
EXEC MASTER..XP_CMDS HELL 'IF EXIST
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedureToFil e.txt
del \\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedureToFil e.txt'
EXEC MASTER..XP_CMDS HELL 'IF EXIST
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedureCCFil e.txt
del \\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedureCCFil e.txt'
--*************** *************** *************** *************** *************** **
--*** END DELETE EXISTING FILES
--*************** *************** *************** *************** *************** **
--*************** *************** *************** *************** *************** **
--*** BEGIN BUILD MESSAGE BODY TEXT FILE
--
--*** If the @BODY parameter if null then we still need to create the
Body
--*** message file but it needs to be blank.
--*************** *************** *************** *************** *************** **
IF NOT @BODY IS NULL
BEGIN
SET @COMMANDSTRING = 'ECHO ' + @BODY + ' >>
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedureMessa ge.txt'
EXEC MASTER..XP_CMDS HELL @COMMANDSTRING
END
ELSE
BEGIN
SET @COMMANDSTRING = 'ECHO >>
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedureMessa ge.txt'
EXEC MASTER..XP_CMDS HELL @COMMANDSTRING
END

--*************** *************** *************** *************** *************** **
--*** END BUILD MESSAGE BODY TEXT FILE
--*************** *************** *************** *************** *************** **

SET @COMMANDSTRING = 'ECHO ::This File is created by sp_blat, a system
stored procedure on all the CRM servers. >>
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd'
EXEC MASTER..XP_CMDS HELL @COMMANDSTRING

SET @COMMANDSTRING = 'ECHO set BLAT_TO=' + @TOEMAIL + ' >>
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd'
EXEC MASTER..XP_CMDS HELL @COMMANDSTRING

SET @COMMANDSTRING = 'ECHO set BLAT_SUBJECT="' + @SUBJECT + '" >>
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd'
EXEC MASTER..XP_CMDS HELL @COMMANDSTRING

SET @COMMANDSTRING = 'ECHO set
BLAT_MESSAGE=\\ File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedureMessa ge.txt
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd'

EXEC MASTER..XP_CMDS HELL @COMMANDSTRING
IF NOT @CCEMAIL IS NULL
BEGIN
SET @COMMANDSTRING = 'ECHO set BLAT_CC=' + @CCEMAIL + ' >>
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd'
EXEC MASTER..XP_CMDS HELL @COMMANDSTRING
END

IF NOT @BCCEMAIL IS NULL
BEGIN
SET @COMMANDSTRING = 'ECHO set BLAT_BCC=' + @BCCEMAIL + ' >>
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd'
EXEC MASTER..XP_CMDS HELL @COMMANDSTRING
END
IF NOT @ATTACHMENT IS NULL
BEGIN
SET @COMMANDSTRING = 'ECHO SET BLAT_ATTACH=' + @ATTACHMENT + ' >>
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd'
EXEC MASTER..XP_CMDS HELL @COMMANDSTRING
IF CHARINDEX(@ATTA CHMENT, '.txt') > 0
BEGIN
SET @ATTACHTEXT = 1
END
END
SET @COMMANDSTRING = 'ECHO \\File-Server\Shared-Data\Blat\blat. exe
%BLAT_MESSAGE% -subject %BLAT_SUBJECT% -to %BLAT_TO%'

IF NOT @CCEMAIL IS NULL
BEGIN
SET @COMMANDSTRING = @COMMANDSTRING + ' -cc %BLAT_CC%'
END

IF NOT @ATTACHMENT IS NULL
BEGIN
IF @ATTACHTEXT = 1
BEGIN
SET @COMMANDSTRING = @COMMANDSTRING + ' -attacht %BLAT_ATTACH%'
END
ELSE
BEGIN
SET @COMMANDSTRING = @COMMANDSTRING + ' -attach %BLAT_ATTACH%'
END
END

IF NOT @BCCEMAIL IS NULL
BEGIN
SET @COMMANDSTRING = @COMMANDSTRING + ' -bcc %BLAT_BCC%'
END

SET @COMMANDSTRING = @COMMANDSTRING + ' >>
\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd'

EXEC MASTER..XP_CMDS HELL @COMMANDSTRING

SET @COMMANDSTRING =
'\\File-Server\Shared-Data\Blat\Produ ction\BlatStore dProcedure.cmd'
EXEC MASTER..XP_CMDS HELL @COMMANDSTRING
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1682
by: paolo | last post by:
is there anyone who has used blat? I have problem when sending a mail from a cgi-script. Any errors arent displayed on the html-page, but the mail is not sent. the code looks like this: #!/usr/local/bin/perl print "Content-Type: text/plain\n\n"; $from = 'test@hotmail.com'; $to = 'paolooracle@hotmal.com'; $subject = 'subject';
3
10878
by: Terri | last post by:
I'm using xp_cmdshell to output a text file from a trigger like this CREATE TRIGGER ON tblApplications FOR INSERT AS DECLARE @FirstName varchar(75) DECLARE @LastName varchar(75) Declare @strcmdshell varchar(150)
4
8105
by: Joel Thornton | last post by:
Whenever something is inserted to a given table, I want to run some shell commands using xp_cmdshell. Would it be a bad idea to put this xp_cmdshell in the INSERT trigger of this table? I understand that when using xp_cmdshell, the sql thread in question waits until xp_cmdshell finishes what it's doing. Does this mean if my xp_cmdshell call takes 30 seconds, that nobody else can insert to this table until my xp_cmdshell and rest of the...
5
8636
by: Narine | last post by:
Hi Folks, I am using an xp_cmdshell sp to start a C# app. This app downloads data files and imports them into DB. It has a logging functionality built-in and when executed from the command line or WE, it records it's progress into a log TXT file. But when executed via xp_cmdshell, it doesn't write into its log file. Is it possible to enable it to write into a log file with xp_cmdshell? Should I be using a different extended sp to...
2
2540
by: Lauren Quantrell | last post by:
I have created a view named viewOutput that shows one column in a table. I insert a row into the table and then I'm using this code to create a file with the text in the single row. This code works fine when I'm signed on with an account that has server admin rights, however it fails when I signin with an account that does not have server admin rights. I'm hoping someone can help me with this.
1
5438
by: Micah Gentry | last post by:
Is there any way to allow a user to use the xp_cmdshell extended stored procedure without giving that user execute permissions to xp_cmdshell in SQL server 6.5? Let me clarify. Lets say I (as the dbo) create a stored procedure called sp_send_err: CREATE PROCEDURE sp_send_err @CompID varchar(20) AS declare @strCMD varchar(255) select @strCMD = "master.dbo.xp_cmdshell 'net send " + @CompID + " ""ERROR!""', no_output" execute (@strCMD)
1
3674
by: TC | last post by:
Hi Steve Some time ago I told you about the "blat" SMTP mailer. You said you would look into it. I'm now planning on using it myself. I've tried the DLL version, & am having a problem with the -install option. It works - ie. it adds the relevant info. to the registry - but it never returns from the call. Access instantly quits! There are no otherr error effects or messages that I can see. So this would make it impractical to use that...
0
1627
by: Jay | last post by:
Not sure who is familiar with the blat program, but I would like to send an email using blat by executing a commmand line using the Shell method. here's my code: /================ Dim RetVal strCommand = "C:\Blat240\full\blat.exe test.txt -to me@myemail.com" RetVal = Shell (strCommand ,vbHide) /================ If I run the string that I assign to strCommand in my "Run" box, it
0
2095
by: misra | last post by:
Hi, I am using a C# code to call blat and send mail. When I send mails with long sentences, the mail automatically is send with multiple lines. However, certain times the body and format of the mail has to look like the following (Have put the body in double quotes) "The following numbers have been Un-validated for - PARIS 20 misrar 31/05/2007 14:13:52 55 misrar 31/05/2007 14:13:52 75 misrar ...
0
10039
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11359
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10543
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4779
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4346
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3370
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.