Change working directory of job started using bin_overrides

I have followed the guide on setting up bin_override scripts so that sbatch is executed over ssh. There is a disclaimer on the guide that stderr and stdout will go to the users home directory:

This wrapper when used with the OOD Job Composer will place any stdout or stderr files in $HOME instead of the usual location of $HOME/ondemand/data/sys/myjobs/projects/default/$JOBID.

Is there a way to get output to go to the usual location, where the usual location is the directory that gets created for each job? Additionally, is there a way to set the working directory to the usual location so that the sbatch script can use relative file paths to access files/data in the job directory?

If I was given the location of the job directory in the bin_override script, then I think adding the –chdir flag to the sbatch command would work. However, the bin_override script just seems to get the contents of the submission script piped to stdin as it’s input, so I don’t know how I would know what path to set with the –chdir flag. Is there additional information about the job that gets passed to the bin_override script that I am not aware of?

Another solution would be to change the working directory within the submission script, but that would be a manual process for each new job, since each new job needs a new path based on its id.

Is there a better solution to this problem?

I actually think that comment may be partly incorrect.

I believe the reason is before submitting the job, we cd to the staged directory and a simple ssh wrapper might not take that directory location into account.

But it appears that, at least for interactive apps, we do use the short form of the --chdir flag -D (in our abstraction its workdir). I expect that we do not do this for the job composer, however.

Since you know we cd to the job directory prior to calling sbatch, I wonder if in your wrapper script you could just attach --chdir $PWD to the command.

Thanks for the help! You are right about the working directory of the bin_override script being the job’s directory. For some reason though, os.getenv('PWD') returns /var/www/ood/apps/sys/myjobs, but os.getcwd() does return the job’s directory. So, I ended up using os.getcwd().

Oh right that makes sense because $PWD is set when the job composer process starts and is not updated due to chdir call. When it forks your bin_override the value of $PWD is same as the parent process.

Glad you found the solution!