Jupyter notebook working directory not set correctly

This seems to work for some users, but not others. The before.sh scripts are the exact same - they are supposed to write to config.py - but the resulting files are different. It would seem that HOME is somehow not defined for one user, but it is hard to tell why. They can run regular batch jobs just fine, and those jobs can see $HOME.

Both output files (with some redaction):

root@ood04:/h/userone/ondemand/data/sys/dashboard/batch_connect/sys/jupyter-22/form/output/0b907c78-9c6d-4d92-bd68-df0f22d68e03# cat config.py
c.JupyterApp.config_file_name = ‘ondemand_config’
c.NotebookApp.ip = ‘
c.NotebookApp.port = 33039
c.NotebookApp.port_retries = 0
c.NotebookApp.password = u’sha1:blah:blah’
c.NotebookApp.base_url = ‘/node/gpu002/33039/’
c.NotebookApp.open_browser = False
c.NotebookApp.allow_origin = '

c.NotebookApp.notebook_dir = ‘/h/userone’
c.NotebookApp.disable_check_xsrf = True
c.NotebookApp.nbserver_extensions = {“jupyterlmod”: True}
root@ood04:/h/userone/ondemand/data/sys/dashboard/batch_connect/sys/jupyter-22/form/output/0b907c78-9c6d-4d92-bd68-df0f22d68e03# cd -
/h/usertwo/ondemand/data/sys/dashboard/batch_connect/sys/jupyter-22/form/output/edeaf236-2093-4539-a0f0-59a6f20f2070
root@ood04:/h/usertwo/ondemand/data/sys/dashboard/batch_connect/sys/jupyter-22/form/output/edeaf236-2093-4539-a0f0-59a6f20f2070# cat config.py
c.JupyterApp.config_file_name = ‘ondemand_config’
c.NotebookApp.ip = ‘
c.NotebookApp.port = 11341
c.NotebookApp.port_retries = 0
c.NotebookApp.password = u’sha1:blah:blah’
c.NotebookApp.base_url = ‘/node/gpu002/11341/’
c.NotebookApp.open_browser = False
c.NotebookApp.allow_origin = '

c.NotebookApp.notebook_dir = ‘’
c.NotebookApp.disable_check_xsrf = True
c.NotebookApp.nbserver_extensions = {“jupyterlmod”: True}

Have you tested with clean home directories? Any differences in .bashrc or something like that? Any additional modules being loaded that differ?

Not sure if this helps, but I don’t set the working dir in before.sh and instead I set --notebook-dir it in the script.sh.erb

# Start Jupyter Notebook
<%= context.jupyter_exec %> --no-browser --ip=${ip} --port=${port} \
  --NotebookApp.base_url=/node/${host}/${port} \
  --NotebookApp.password="${JUPYTER_PASSWORD}" \
  --NotebookApp.disable_check_xsrf=True \
  --notebook-dir=${HOME} \
  --NotebookApp.allow_origin='*' \
  --NotebookNotary.db_file=':memory:'

There may also be an environment variable or python scripts in their HOME that do something different for those specific users.