Basic program to monitor path

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

r.julia
Participant
Posts: 23
Joined: Tue Jan 24, 2006 8:04 am

Basic program to monitor path

Post by r.julia »

Hi,

I want a DS basic job to monitor a path on a unix server and sends a mail if files there are longer than 2hours. Could someone tell me if theres a similar job here please, or give me some idea about this. I am completely new to basic programming. I could do this easily in shell or C.

Thanks

Julia
Datastage is pretty interesting
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

So, write a shell script and call it from a DS Sequence job command stage or write a Batch job to loop and use CALL DSExecute to periodically run the same shell script.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
r.julia
Participant
Posts: 23
Joined: Tue Jan 24, 2006 8:04 am

followup

Post by r.julia »

Could you please give me an example of the batch jobs to call the script? I dont think I have came accross this in my short(7weeks) DS career.

Thanks

Julia
Datastage is pretty interesting
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Using DS Director, from menu Tools --> Batches --> New. In the blank job control canvas, type in this:

UnixCmd="hostname"
CALL DSExecute("UNIX", UnixCmd, ScreenOutput, ReturnCode)
CALL DSLogInfo("The UnixCmd shows this to the screen -->":ScreenOutput, "Test")
CALL DSLogInfo("The UnixCmd had this exit value -->":ReturnCode, "Test")


All DS APIs are documented in your DS BASIC manual available under your Start button, Ascential, Online Documentation. You can write anything you need to do. Consider putting this logic into a loop with a sleep statement to periodically execute your script. Consider exiting the loop (and thus the job) at a predetermined time or exit condition (maybe check for an exit file in a certain directory).
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
r.julia
Participant
Posts: 23
Joined: Tue Jan 24, 2006 8:04 am

followup

Post by r.julia »

Thanks Kenny.I will try it.

Julia
Datastage is pretty interesting
r.julia
Participant
Posts: 23
Joined: Tue Jan 24, 2006 8:04 am

followup

Post by r.julia »

Hi Kenny,
Do I really need to write a loop statement again? I already wrote a working script that does the job. Wouldnt it be enough just to execute the script in DS? I also included a delay in the unix script.

Please advise

Julia
Datastage is pretty interesting
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Do whatever you want. Once a job calls a script there's no way to stop the job (without a kill) until the script exits. If your script does the checks and returns a status value, then your job could do the loop. Either Batch or Sequence has the ability to loop.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
avi21st
Charter Member
Charter Member
Posts: 135
Joined: Thu May 26, 2005 10:21 am
Location: USA

DSJOB RUN status code

Post by avi21st »

r.julia wrote:Hi Kenny,
Do I really need to write a loop statement again? I already wrote a working script that does the job. Wouldnt it be enough just to execute the script in DS? I also included a delay in the unix script.

Please advise

Julia
In your script you need to check the return status...say I generally use a DSJOB -RUN to run the Datastage sequencers from Unix...

here we check for the return status..there are lot of scripts available..one I saw by kcbland...I took help from him once to create a script which also I had posted here

In general the return from the DSJOB -RUN are

Ready to run- Job Status

# 1 "Finished"
# 2 "Finished with Warning (see log)"
# 9 "Has been reset"
# 11 "Validated OK"
# 12 "Validated (see log)"
# 21 "Has been reset"
# 99 "Compiled"

Wait -Job Status

# 0 "Running"

Failure- Job Status (reset job)


# 3 "Aborted"
# 8 "Failed validation"
# 13 "Failed validation"
# 96 "Aborted"

Track them in your script and then have a decision based loop
# 97 "Stopped"
# 98 "Not Compiled"
Avishek Mukherjee
Data Integration Architect
Chicago, IL, USA.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Create a job sequence.
In that job sequence use an Execute Command activity to run your script.

Follow it with a Routine activity that invokes UtilityWarningToLog (or UtilityInfoToLog) to log any message, and a Notification activity to send email.

Between the Execute Command activity and the next activity specify a custom trigger based either on the shell script's exit status or it's output.

If you have DataStage version 7.5 you can enclose all of the above in a loop between a StartLoop and an EndLoop activity. In this case you will need a second path (where no email needs to be sent) emanating from the Execute Command activity, and join both streams using a Sequencer prior to the EndLoop activity. You would also need to determine a mechanism for advising the loop to exit, such as a file coming into existence.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
r.julia
Participant
Posts: 23
Joined: Tue Jan 24, 2006 8:04 am

folowup

Post by r.julia »

Hi Ray,
I tried executing the script with the execute command but it doesnt work.In the command line, I put the path to the script /home/A/B/script.sh . What about the parameters?

Thanks

Julia
Datastage is pretty interesting
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

"Doesn't work" in what sense? What does the job's log say when the command is execute?

Not sure what you are asking about the parameters. There is a specific 'box' for them as well, put any you need there. It will combine the two before the command is executed.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

What is not working?
Place your path and the shell name in the 'Command' option and Parameters in the available Parameters option.
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
r.julia
Participant
Posts: 23
Joined: Tue Jan 24, 2006 8:04 am

followup

Post by r.julia »

The Execute Command applet has two inputs COMMAND and PARAMETERS. In the command, I put the path where the script is located ( /home/A/B/script.sh - I put sth like this). In the parameter box, I didnt put anything.

But the script did not execute.

I also tried this option:

UnixCmd="sd.dfd.com" (hostname)
CALL DSExecute("UNIX", 'sh -x /home/A/B/script.sh', ScreenOutput, ReturnCode)
CALL DSLogInfo("The UnixCmd shows this to the screen -->":ScreenOutput, "Test")
CALL DSLogInfo("The UnixCmd had this exit value -->":ReturnCode, "Test")

I tried to execute this first to see if it works, before proceeding with the loop statement.

Thanks
Julia
Datastage is pretty interesting
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

Parameters need not be be passed if not required. But you may need do mention clearly, about what is not working.
Are you getting any warning/Error? Or the output is not expected?
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
r.julia
Participant
Posts: 23
Joined: Tue Jan 24, 2006 8:04 am

folowup

Post by r.julia »

THe script reads from an input file. When I execute it normally it works, but when I execute from DS, it says cannot open file in the log. I checked the rights and everything looks ok.

Thanks

Julia
Datastage is pretty interesting
Post Reply