Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 osql issue

Author  Topic 

raagi2000
Starting Member

6 Posts

Posted - 2005-11-30 : 09:50:24
hello

We are running osql to trap the failed jobs in all the production servers in one log file . We are on SQL 2000 SP3a. it does the good job except for the
part it produces the unnecessary output like one in the below even there is no failed jobs

Here is where i need help from you guyz if there is no failed jobs on a server i do not need to print anything on the log file
e-g osql -SBOSTPNYD2 -E -ic:\jobchecker\jobchecker.sql >>c:\jobchecker\jobchecker.log

=============================
------PRODUCTION SERVERS-----
=============================
1> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15> 16> 17> 18> 19> 20> 21> 22> 23> 24> 25> 26> 27>

------------------------------------------------------------------------------
--------------------------------------------------
BOSEPNYD2


Job Name Step Name
Message Run Date
------------------------------ ------------------------------
---------------------------------------- -----------

1> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> 15> 16> 17> 18> 19> 20> 21> 22> 23> 24> 25> 26> 27>

------------------------------------------------------------------------------
--------------------------------------------------


its reasonable to print for BOSTPNYD3 because it had failed jobs like below

BOSTPNYD3

Job Name Step Name
Message Run Date
------------------------------ ------------------------------
---------------------------------------- -----------
Import Orders from Relizon Import orders/conf file
Executed as user: GLOBAL\USSQLAdmin. Mai 20051127
Import Orders from Relizon (Job outcome)
The job failed. The Job was invoked by 20051127

any help on this would be greatly appreciated
THANKS

bakerjon
Posting Yak Master

145 Posts

Posted - 2005-11-30 : 10:46:52
Not sure if this helps, but I'll post a script of something we do for job checking. It appears as though you are logging everything to a file. We have elected to log everything to tables, so we can track them over time, manipulate the data in T-SQL, etc. We log to a local database on each server, DBA, then DTS the data nightly to a repository for all servers, DBA_Repository. Then we do some reporting via reporting services, and setup subscriptions, etc. Anyway, here's the job_status script (thanks also to Dennis Vroom for help with this). When we have no failures, it produces no rows in the table.

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON
GO

use DBA
go

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[usp_get_job_status]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[usp_get_job_status]
GO



CREATE PROCEDURE usp_get_job_status
/*
Author: Jon Baker
Date : 7/25/2005
Paramaters : None

Test Data :
usp_get_job_status
select * from dba.dbo.dba_job_status


Purpose : To collect data for daily monitoring of job status


Revisions :

*/
AS

set nocount on

DECLARE @rc int
DECLARE @errmsg varchar (256)


--If the logging table does not exist, create it
if not exists (select 1 from dba.dbo.sysobjects where xtype = 'u' and name = 'dba_job_status')
BEGIN

CREATE TABLE dbo.dba_job_status
(
collect_time datetime not null,
server_name sysname not null,
instance_id int not null,
job_name sysname null,
step_name sysname null,
message nvarchar(2048) null,
run_date int null,
run_time int null,
run_duration int null,
CONSTRAINT PK_dba_job_status PRIMARY KEY (collect_time desc, instance_id desc)

)
if @@error <> 0
BEGIN
set @errmsg = 'create table failed!'
goto ERRORPROC
END
END

declare @now datetime
set @now = getdate()
declare @max_instance_id int
set @max_instance_id = isnull((select max(instance_id) from dbo.dba_job_status),0)

INSERT INTO [DBA].[dbo].[dba_job_status]
(
[collect_time],
[server_name],
[instance_id],
[job_name],
[step_name],
[message],
[run_date],
[run_time],
[run_duration]
)
SELECT
@now, @@servername,
H.instance_id, J.name, H.step_name,
H.message, H.run_date, H.run_time, H.run_duration
from msdb.dbo.sysjobs J
join msdb.dbo.sysjobhistory H
on J.job_id=H.job_id
where H.run_status=0 and H.instance_id>@max_instance_id
order by H.instance_id desc


if @@error <> 0
BEGIN
set @errmsg = 'INSERT failed!'
goto ERRORPROC
END
ELSE
goto ENDPROC

ERRORPROC:
BEGIN

RAISERROR (@errmsg, 16, 1)
RETURN (-1)
END


ENDPROC:
BEGIN
Return (0)
END


If you visit my blog (see signature), I actually talked more about this solution recently.

HTH


Jon
-Like a kidney stone, this too shall pass.

http://www.sqljunkies.com/weblog/outerjoin
Go to Top of Page
   

- Advertisement -