SQL Server Performance Forum – Threads Archive
osql issue
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 thepart 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:jobcheckerjobchecker.sql >>c:jobcheckerjobchecker.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: GLOBALUSSQLAdmin. 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
If I’ve understood you correctly what you want to remove is the numbering? If so use the -n switch to remove numbering. If you also want to remove the headers (i.e. the dashed lines) use -h-1. e.g. osql -SBOSTPNYD2 -E -ic:jobcheckerjobchecker.sql >>c:jobcheckerjobchecker.log -n -h-1 Hope that helps.
quote:Originally posted by raagi2000
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:jobcheckerjobchecker.sql >>c:jobcheckerjobchecker.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: GLOBALUSSQLAdmin. 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
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:jobcheckerjobchecker.sql >>c:jobcheckerjobchecker.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: GLOBALUSSQLAdmin. 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
Karl Grambow www.sqldbcontrol.com
Thanks Carl for your valuable input I am running the sql to pull the failed jobs select substring (j.name,1,30) ‘Job Name’,
substring (h.step_name,1,30) ‘Step Name’,
substring (h.message,1,40) ‘Message’,
h.run_date ‘Run Date’
from msdb.dbo.sysjobhistory h,msdb.dbo.sysjobs j
where h.job_id = j.job_id
and message not like ‘%succeeded%’
and (run_date >= @yesterday and run_date <= @today) how can i modify this sql so that it can return the output only if there is a failed job, here i wanted to see the column headers etc. If no failed jobs i do NOT want to see any output including column header or on the log file. above is the sql i am firing when i call the jobchecker batch script. thanks
What you could do us check to see whether there are any records by using an exists clause, and if there are then run the select statement.<br /><br />Incidentally, you’d be better off looking at the sysjobservers table to find out if the job failed.<br /><br />Also, you might want to watch out for the clauses you’re using for datetime searches, because you’ve got to allow for some jobs running several times a day.<br /><br />I wrote a massive job monitoring system that started off much like yours seems to be starting off and it grew and grew and grew. Lots of fun.<br /><br />By the way, don’t believe what BOL tells you about the last_run_time column in sysjobservers. It’s not seconds. in this column, 120001 = 12:00:01 <img src=’/community/emoticons/emotion-1.gif’ alt=’

]]>