Skip to content

Instantly share code, notes, and snippets.

@soxofaan
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soxofaan/6f4d79a8b98954536093 to your computer and use it in GitHub Desktop.
Save soxofaan/6f4d79a8b98954536093 to your computer and use it in GitHub Desktop.
Gnu screen trick to launch ipython notebook within screen session non interactively
#!/bin/sh
# set -x
# set -e
sessionname=ipython-notebook
if screen -list | grep $sessionname ; then
echo "Screen session $sessionname is already running."
echo "not doing anything"
else
echo "Starting iPython notenbook in screen session '$sessionname'"
# A bit of explanation:
# -dm: start screen in "detached" mode
# -S: give the session a name
# bash -c 'source ....': launch a bash shell and source virtual enviroment settings before launching ipython
# Now, pick one of the following options:
### Use standard/system wide iPython notebook
screen -dm -S $sessionname ipython notebook
### Use iPython from a virtualenv.
# screen -dm -S $sessionname bash -c 'source virtualenv/bin/activate; ipython notebook'
### Use iPython form Anaconda environment
# screen -dm -S $sessionname bash -c 'source activate ipython2; ipython notebook'
echo "iPython Notebook should be running now, have fun!"
fi
echo "Reattach to the screen session (e.g. to shut down) with:"
echo " screen -r $sessionname"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment