Page 1 of 3

Log to file

Posted: Wed Feb 15, 2012 4:26 am
by mdbatra
Hi All,
How do we dump the latest log of a job to a text file? there's is a requirement where we need to send the log to client in case of a failure. Due to time constaint, i was able to browse a few of the posts on this topic, but didn't quite get it.

Would prefer if somebody can guide using BASIC/server job ?

Posted: Wed Feb 15, 2012 4:38 am
by pandeesh
i had tried the same some months ago, that's here:
viewtopic.php?t=141047
I believe that will help you more

Posted: Wed Feb 15, 2012 4:39 am
by mdbatra
even if any guide could be provided on fetching the EVENT_ID for the first event of the latest run, i would be able to get the desired results.
Would appreciate any help on this.

Posted: Wed Feb 15, 2012 4:49 am
by pandeesh

Code: Select all

#                      maillog.sh                                          #
#Author:Pandeeswaran                                                       #
#This is used to retrieve the warnings and fatals alone in the recent run  #

START_ID=`/opt/app/dstage/DataStage752/Ascential/DataStage/DSEngine/bin/dsjob -server servername -user username -password pwd -logsum -type STARTED Projectname Jobname| nawk 'ORS=(FNR%2)?FS:RS' | grep Starting | tail -1 | awk '{print $1 }'`

WARN_ID=`/opt/app/dstage/DataStage752/Ascential/DataStage/DSEngine/bin/dsjob -server Servername -user username -password pwd -logsum -type WARNING Projectname Jobname| grep WARNING | awk '{print $1 }'`

FATAL_ID=`/opt/app/dstage/DataStage752/Ascential/DataStage/DSEngine/bin/dsjob -server Servername -user username -password pwd -logsum -type FATAL Projectname Jobname| grep FATAL | awk '{print $1 }'`

echo "WARNINGS AND FATALS:" > /path/log.txt

ALL_ID=`echo "${WARN_ID} ${FATAL_ID}"` 

for ID in ${ALL_ID} 
do 
if [[ "${ID}" -gt "${START_ID}" ]] 
then 
ALL_DTL=`/opt/app/dstage/DataStage752/Ascential/DataStage/DSEngine/bin/dsjob -server Servername -user username -password pwd -logdetail Projectname Jobname ${ID}` 
echo ${ALL_DTL}\n >> /path/log.txt
echo "\n" >>/path/log.txt
fi 
done 
(cat /path/log.txt)|mailx -s  "find the fatals and warnings" "mailid"

exit 0

Posted: Wed Feb 15, 2012 4:51 am
by mdbatra
Thanks pandeesh, but i would prefer the solutions given in your thread earlier, as i am not very keen to use UNIX for this solution. I should be able to manage now from BASIC. let me try , will get back. and thanks so much for this quick response.

Posted: Wed Feb 15, 2012 4:53 am
by pandeesh
I believe you have BASIC guide.Everything is documented over there.
You can check

Code: Select all

DSJ.LOGSTARTED

Posted: Wed Feb 15, 2012 5:02 am
by mdbatra
yeah...i am just working on those LOGSTARTED/LOGANY to give me the latest start and event ID, so that i can loop through.

Thanks to your posts dear :)

Posted: Wed Feb 15, 2012 5:06 am
by pandeesh
Please resolve the topic, once your problem gets solved.

Thanks for your co-operation

Posted: Wed Feb 15, 2012 6:39 am
by mdbatra
LOGSTARTED and LOGANY in DSNewestLogId is yielding the same results, which is the last event id for latest run :(

i am using code(this is just a draft version):

job = pJobName
log_file = pJobLogFile

control = DSJobName

Call DSLogInfo("job name is ":job,control)
Call DSLogInfo("Output log file is ":log_file,control)

hJob = DSAttachJob(job,DSJ.ERRFATAL)

Call DSLogInfo("job attached now",control)

st_id= DSGetNewestLogId(hJob,DSJ.LOGSTARTED)
Call DSLogInfo("Start id is: ":st_id, control)
end_id= DSGetNewestLogId(hJob,DSJ.LOGANY)
Call DSLogInfo("End id is: ":end_id, control)

please let me know if i am missing anything here.

Posted: Wed Feb 15, 2012 7:37 am
by pandeesh
I think you are facing the same issue whichever i faced.
Please reread my older post and finally you can find the suggestion provided by evee1:

Code: Select all

However, when I changed the routine to do the following instead:
Code:
NewestStartId = DSGetNewestLogId(DSJ.ME, DSJ.LOGSTARTED)
NewestLogId = DSGetNewestLogId(DSJ.ME, DSJ.LOGANY)
the routine is able to locate the starting event correctly.  
But i din't face any issues in the unix script i have posted(Because of this only, i went for unix solution at that time :) )

Posted: Wed Feb 15, 2012 8:02 am
by mdbatra
But wouldn't DSJ.ME point to the current job. I am writing the control in a separate job to read the log of a different job.

Posted: Wed Feb 15, 2012 8:07 am
by chulett
Yes, so you'll need to get a handle to that other job and use that rather than DSJ.ME and release it when you are done.

Posted: Wed Feb 15, 2012 8:10 am
by mdbatra
That's what the problem is. If you can have a quick look at the sample code above, i used a separate job handle for that job.

But the problem here is LOGSTARTED & LOGANY are returning same event id(last event id for latest run), instead of last start event id and last event id of that particular job, respectively.

Posted: Wed Feb 15, 2012 8:13 am
by pandeesh
Honestly, i have never tried that in routine and implemented the same in shell script.

Posted: Wed Feb 15, 2012 8:16 am
by mdbatra
i understand pandeesh :) ...but i am interested to know why this things is not wondering. I would be left with no other option than to use the unix solution, but my first love is BASIC :)