Check if a job ran at 5AM.

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
syang@collaborative.com
Premium Member
Premium Member
Posts: 33
Joined: Tue Sep 02, 2014 7:43 am

Check if a job ran at 5AM.

Post by syang@collaborative.com »

Hi guys,

Here is the requirements: trigger a job that is supposed to run everyday at 5AM through the DS Director; if for some reason, that job didn't run.

I will be writing a batch script. I'm wondering how I can check if the job ran at 5AM. Is there a way to check for the job status of a specific job depending on the date/time?

Thanks.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

It's simple enough to check the date/time that a job last ran. Or to check and see if a job is running. Will either of those work for you? Both would use dsjob -jobinfo off the top of my head, the former would parse out and check the last runtime while the latter would run at say 5:01AM and check for a status of RUNNING.

I only ask in case it runs multiple times during the day and you want to check a specific iteration of the job.
-craig

"You can never have too many knives" -- Logan Nine Fingers
syang@collaborative.com
Premium Member
Premium Member
Posts: 33
Joined: Tue Sep 02, 2014 7:43 am

Post by syang@collaborative.com »

That would be great. Where can I go to get the exact syntax for that? I've been trying to check for the job status, 0 for running and 99 for not running, but have had no success at writing an IF/ELSE statement.

This is the code I used to check the job status:
%DsJob% -server %Server% -user %username% -password %password% -jobinfo %Project% %JobName2%
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Your dsjob syntax looks fine, the challenge would be in parsing the output. Rather than a batch file, write a UNIX script with grep for that... I'm assuming you can still do that in your version with whatever is there similar to MKSToolkit. Or is that no longer possible?

If not, then perhaps something like this would help. Redirect the output of the command to a file so you can interrogate it multiple times if you need to. My advice - look for the status words like RUNNING in the output rather than codes.

Give it a shot and if you still need help, post your script/batch and people will be happy to help with the gory details.
-craig

"You can never have too many knives" -- Logan Nine Fingers
syang@collaborative.com
Premium Member
Premium Member
Posts: 33
Joined: Tue Sep 02, 2014 7:43 am

Post by syang@collaborative.com »

Sorry I haven't replied sooner. Thanks for the input guys. This is the simple frame work that I have.

Code: Select all

%DsJob% -server %Server% -user %username% -password %password% -report %Project% %JobName1% >> %LogFileDir%
	
	:: sets the job_start_time variable to the date.
	:: example: "Job start time=2014-11-06 18:02:08" set to "2014-11-04"
	for /F "delims=" %%a in ('FINDSTR /C:"Job start time=" %LogFileDir%') do set job_start_time=%%a
	
	echo. >> %LogFileDir%
	
	echo %job_start_time:~18,10% >> %LogFileDir%
	
	echo. >> %LogFileDir%
	
	echo %DsxDate% >> %LogFileDir%
	
	IF "%job_start_time:~18,10%" EQU "%DsxDate%" (
	goto job_date_match
	
	)else (
	goto job_not_match
	
	)

:job_date_match
	echo True. >> %LogFileDir%
	:: do nothing
	GOTO end_script
	
:job_not_match
	echo False. >> %LogFileDir%
	%DsJob% -server %Server% -user %username% -password %password% -run -wait -jobstatus -warn %warn_limit% %Project% %JobName1%
	GOTO end_script
This will match the date of the latest job start time.

Thanks again.
Post Reply