473,738 Members | 1,949 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 7666
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
1677
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
10848
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
8092
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
8618
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
2533
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
5431
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
3665
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
1620
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
2086
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
8968
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
8787
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
9473
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
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4824
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.