Jump to content
  • Announcements

    • admin

      PBS Forum Has Closed   06/12/17

      The PBS Works Support Forum is no longer active.  For PBS community-oriented questions and support, please join the discussion at http://community.pbspro.org.  Any new security advisories related to commercially-licensed products will be posted in the PBS User Area (https://secure.altair.com/UserArea/). 
ashley

Help: Using a hook to write to job's output file

Recommended Posts

Hi,


 


Hoping someone here may be able to help me.


I would like to write a hook, which can append some information to the job's output file.


However I can't find any interface which may allow me to either write to the file, or find the name and location of the file.


 


I am basically trying to depulcation an epilogue script which does this. However I need it to be a hook, as PBS does not allow both a execjob_epilogue hook and an epilogue script to be run.


 


Can anyone provide any suggestions?


 


Thanks,


Ashley


Share this post


Link to post
Share on other sites

Hi Ashley, an enhancement to the hooks interface to make this easier is planned for a future release.  For now, you can do something like this:



import pbs

e=pbs.event()
j=e.job

if j.in_ms_mom():

    pbs_home="/var/spool/PBS"

    if "o" in str(j.Keep_Files):
        jobfile=str(j.Output_Path).split(":", 1)[1]
    else:
        jobfile=pbs_home + "/spool/" + j.id +".OU"

    jobout = open (jobfile,'a')
    jobout.write("PBS epilogue BEGIN\n")




As an execjob_epilogue hook, this should accomodate any combination of qsub -o and -ko options (remember to set pbs_home in the example script above to the path you use in your environment).


 


This only handles stdout, but could easily be extended to accomodate stderr if you desire.


 


I hope this is helpful!


 


-Scott


Share this post


Link to post
Share on other sites

Hi Scott,


 


Sorry about taking so long to reply. Just got time to finish the hook this afternoon.


What you provided worked well, and we have implemented it in the test cluster and it seems to be working. Will try it on the production cluster in the morning.


 


For reference, in case other are interested, here is the full script we have used.



import pbs
import sys

try:
e = pbs.event()
j = e.job

if j.in_ms_mom():
pbs_home="/var/spool/PBS"
if "o" in str(j.Keep_Files):
jobfile=str(j.Output_Path).split(":", 1)[1]
else:
jobfile=pbs_home + "/spool/" + j.id +".OU"

walltime = j.resources_used['walltime']
mem = j.resources_used['mem']
cput = j.resources_used['cput']
pbs.logjobmsg(j.id, "HOOK. writing to jobfile: %s " % jobfile )

outfile = open (jobfile,'a')

outfile.write("\n-----\n")
outfile.write("PBS Job %s\n" % j.id)
outfile.write("CPU time : %s\n" % cput)
outfile.write("Wall time : %s\n" % walltime)
outfile.write("Mem usage : %s\n" % mem)

outfile.close()

e.accept()

except SystemExit:
pass
 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×