Difference between revisions of "WorkingOnServers/DisplayEnvironmentTricks"

From mn/geo/geoit
Jump to: navigation, search
(A trick for working with SSH, and screen)
Line 24: Line 24:
  
 
What is happening here is that everytime you log in, the .bash_profile file creates a new file in your home directory, specific to your user, and the hostname. Whenever you log out and log back in, that file is updated with the appropriate DISPLAY information. In the .bashrc file, we've created a PROMPT_COMMAND that will read that file everytime you hit return in your shell. This can cause some annoyances if the file does not exist, for example if you use the 'su' command to become another user. However, overall it works quite well, such that when you return to a running ''screen'' session, the DISPLAY variable will be updated and you'll be able to send X-display windows back to your client machine.
 
What is happening here is that everytime you log in, the .bash_profile file creates a new file in your home directory, specific to your user, and the hostname. Whenever you log out and log back in, that file is updated with the appropriate DISPLAY information. In the .bashrc file, we've created a PROMPT_COMMAND that will read that file everytime you hit return in your shell. This can cause some annoyances if the file does not exist, for example if you use the 'su' command to become another user. However, overall it works quite well, such that when you return to a running ''screen'' session, the DISPLAY variable will be updated and you'll be able to send X-display windows back to your client machine.
 +
 +
=A script for keeping track of screens=
 +
 +
Often you may have several <code>screen</code> sessions running. It is recommended to start <code>screen</code> with the following command:
 +
<pre>
 +
screen -S my_description
 +
</pre>
 +
 +
Where ''my_description'' is some string that has meaning to you as a 'session' identifier. If only one <code>screen</code> session is running then simply <code>screen -r</code> will reconnect. However, if you have more, things can get complicated. The following script is helpful in such a case:

Revision as of 23:33, 26 September 2011

A trick for working with SSH, and screen

Often you'll want to ssh to a server, start a job and leave. Knowing that you want the job to stay alive after you log out, you can just use:

nohup myjob.sh > nohup_output.nh

But sometimes you'd rather have an actual term or shell session stay alive. This is often the case when working with ipython. The problem is that your $DISPLAY environment variable may change, so that when you log into the machine later, what screen thinks is the present $DISPLAY variable will no longer be current and you'll get errors.

My workaround for this has been the following:

1 On the host machine, that is the one you are logging into, in your .bash_profile (which gets read when you log in via ssh) you should add the line:

   echo "export DISPLAY=$DISPLAY" > .display.`whoami`.`hostname`
  

2 Again, on your host machine,make sure the following is in your .bashrc:

   ## set the prompt command to read the .disply file
   export PROMPT_COMMAND=". ~/.display.`whoami`.`hostname`"
  


What is happening here is that everytime you log in, the .bash_profile file creates a new file in your home directory, specific to your user, and the hostname. Whenever you log out and log back in, that file is updated with the appropriate DISPLAY information. In the .bashrc file, we've created a PROMPT_COMMAND that will read that file everytime you hit return in your shell. This can cause some annoyances if the file does not exist, for example if you use the 'su' command to become another user. However, overall it works quite well, such that when you return to a running screen session, the DISPLAY variable will be updated and you'll be able to send X-display windows back to your client machine.

A script for keeping track of screens

Often you may have several screen sessions running. It is recommended to start screen with the following command:

screen -S my_description

Where my_description is some string that has meaning to you as a 'session' identifier. If only one screen session is running then simply screen -r will reconnect. However, if you have more, things can get complicated. The following script is helpful in such a case: