Page 1 of 2

Basic program to monitor path

Posted: Tue Oct 03, 2006 7:03 am
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

Posted: Tue Oct 03, 2006 7:16 am
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.

followup

Posted: Tue Oct 03, 2006 7:30 am
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

Posted: Tue Oct 03, 2006 7:45 am
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).

followup

Posted: Tue Oct 03, 2006 7:56 am
by r.julia
Thanks Kenny.I will try it.

Julia

followup

Posted: Tue Oct 03, 2006 9:11 am
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

Posted: Tue Oct 03, 2006 9:16 am
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.

DSJOB RUN status code

Posted: Tue Oct 03, 2006 12:37 pm
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"

Posted: Tue Oct 03, 2006 4:38 pm
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.

folowup

Posted: Thu Oct 05, 2006 6:28 am
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

Posted: Thu Oct 05, 2006 6:52 am
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.

Posted: Thu Oct 05, 2006 6:53 am
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.

followup

Posted: Thu Oct 05, 2006 7:05 am
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

Posted: Thu Oct 05, 2006 7:13 am
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?

folowup

Posted: Thu Oct 05, 2006 7:20 am
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