2
$\begingroup$

With the Sun Grid Engine, how can I get the directory where the job script is located, within the job script?

I need this so I can start the script with

cd script-location

to make sure it'll have access to all the necessary files. So far I have hard-coded the script directory into each script, which makes it much too easy to make mistakes.

$\endgroup$
  • $\begingroup$ You can find out your current working directory using the PWD environment variable. Also, an absolute path for script-location should ensure you change to the right directory, regardless of your working directory when the script starts (you're already doing this). Is that what you're looking for? I typically code in paths using environment variables, if possible, to make hacking scripts easy. $\endgroup$ – Geoff Oxberry Apr 19 '13 at 16:06
2
$\begingroup$

The #$ -cwd option to your job script will guarantee that SGE places you in the submission directory automatically so that you don't have to do cd script-location manually. The environment variable SGE_O_WORKDIR is defined and available to your job script as the working directory that you submitted it from as well.

These and other things are described in the man page for qsub.

$\endgroup$
  • $\begingroup$ I found -cwd, but I misunderstood it as referring to the locations of the job.o* and job.po* files. SGE_O_WORKDIR sounds like it should definitely work. Of course everything is documented somewhere, but it's not always obvious where (google is usually better than a man page, but apparently not in this case) ... and experimenting with job scripts is both tedious and frustrating because of the waiting time. Thank you for the answer! $\endgroup$ – Szabolcs Apr 19 '13 at 16:42
  • $\begingroup$ My pleasure. I didn't mean to be snarky about the man page. Just marking it for future reference for others. $\endgroup$ – Bill Barth Apr 19 '13 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.