Groups | Blog | Home
all groups > sql server (alternate) > december 2004 >

sql server (alternate) : sql server job output file -passing it onto second step


tram
12/27/2004 11:07:51 AM
How do we pass on the step1 output file to step2 of the same job? I
would like to know the current job's output file programmetically,
instead of hard coding it. Any idaes would be appreciated.

Thanks
SQLDBA
12/27/2004 12:41:11 PM
It would be helpfull if you can explain what you are doing in each
step. If these steps are calling a stored proc/dts ect... do you know
the output file name ? If so, its easy to pass them as input parameters
to that job. Need more info on what you are trying to acomplish
here....
treschaud NO[at]SPAM hotmail.com
12/27/2004 6:17:52 PM
I don't completely understand your question. Here's what I think you
mean: Job1 runs a script (or single query) that generates command
statements. Job2 runs the output from Job1.

One way to do this is use use the command line switches of the isql.exe
(query analyzer). Search for ISQL in books online to see a complete
list of the switches.

use -o to specify an output file.
use -i to specify an input.

Job1's output file would be Job2s input file.

Another way to generate sql, then run it, is to use the sp_executesql
stored procedure. The coding for this can get rather ugly and complex,
if you have to setup cursors. Sometimes isql command line is a simple
quick and dirty solution.

Hope this is what you were for.

Dave

[quoted text, click to view]
Erland Sommarskog
12/27/2004 10:07:31 PM
tram (tram_e@hotmail.com) writes:
[quoted text, click to view]

It appears to be in msdb.dbo.sysjobsteps.output_file. You could also
call sp_help_jobstep and get the data from there.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
tram
12/28/2004 5:38:15 AM
Thanks for responses. In the first step, I am doing tsql backup
maintenance command. If it fails, in the second step, I am using mail
procedure to send mail to DBAs. My intention is to attach the first
step's output file in the mail so that DBAs could review the log
without logging on to server.

1) I don't want to hard code the file name as it varies from jobn to
job.
2) I need to extract the output file name from one of the jobs tables
for which I need to give the jobID. How to find out the job ID for the
current step?


[quoted text, click to view]
tram
12/28/2004 5:38:20 AM
Thanks for responses. In the first step, I am doing tsql backup
maintenance command. If it fails, in the second step, I am using mail
procedure to send mail to DBAs. My intention is to attach the first
step's output file in the mail so that DBAs could review the log
without logging on to server.

1) I don't want to hard code the file name as it varies from jobn to
job.
2) I need to extract the output file name from one of the jobs tables
for which I need to give the jobID. How to find out the job ID for the
current step?


[quoted text, click to view]
tram
12/29/2004 4:34:10 AM
Erlnad,

Thanks for your constructive reply. I am using db maintenance plan and
in sql sglagent job window I am storing the output in file. In case of
step 1 fails, my aim is to extract the output file name of step 1 and
passit as an attachment to second step.
Erland Sommarskog
12/29/2004 10:22:36 PM
tram (tram_e@hotmail.com) writes:
[quoted text, click to view]

Yeah, I know that by know, but I think you need to give up that path. I
can't think of a way how a T-SQL batch could find which job it's in -
after all the same batch could be running from somewhere else.

Possibly if you run an ActiveX task and use the SQLAgent object, this
information is available.

My idea was to keep it simple.

But you will have to step out of the realms of the maintenance job and
roll your own. Which should not be a big deal.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
Dave
12/30/2004 12:30:58 PM
How about this:

Specifiy the output file on the advanced tab of step1. (This way the
filename doesn't change.) Use a third step to make date copy of the
file.

Now you can hard code your failure step (step 2).

Make a step 3 that always fires. Here's sample Dos command line code
to do this.
Rem -----------------------------
Rem -- Parse date and time into xdate and xtime variables
for /F "tokens=2-4 delims=/ " %%a in ('echo %date%') do (set
xdate=%%c%%b%%a)
for /F "tokens=1-2 delims=:,." %%a in ('echo %time%') do (set
xtime=%%a%%b)

set outfile=c:\backup.log
set newfile=backup%xdate%%xtime%.log

rem -- rename the file
ren %outfile% %newfile%
Rem -----------------------------

Dave

[quoted text, click to view]
Erland Sommarskog
1/1/2005 10:09:48 PM
tram (tram_e@hotmail.com) writes:
[quoted text, click to view]

Turns out that I was wrong. Eavesdropping on a discussion between some
of my MVP colleagues, I learnt that SQL Agent has a couple of tokens
that you can pass to a job step, including the job id and the step number.

For a list of available tokens, look in Books Online in the sp_add_jobstep
topic.

Also, see http://www.sqldev.net/sqlagent/SQLAgentStepTokens.htm for some
tips.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
AddThis Social Bookmark Button