- Renaming a RAC cluster - 27/09/2018
- Stop/Start all RAC databases at once - 26/09/2018
- RMAN Backup script - 08/11/2017
What is the screen command ?
When you have long running jobs, you need to keep them active when you disconnect from server.
The screen command allows you to detach your terminal from you session.
By doing this there is no link between your session and your terminal and you can disconnect from server while your terminal and your jobs keep running.
Even better, once you reconnect to the server you can reattach the terminal to your new session and find your terminal exactly like you left it.
How does it work ?
Connect to your server with you username and password and issue the screen command:
[cmodiano@veelaora001 ~]$ screen
you can also name your terminal with:
[cmodiano@veelaora001 ~]$ screen -S name
Now you can run your long operation, for example a long sql script:
[cmodiano@veelaora001 ~]$ sqlplus test/test @mylongrunningscript.sql
once your script is running, press “Ctrl-a” and then “Ctrl-d” to detach your terminal.
Your terminal is now detached. You can start more than one screen at a time if you want to run multiple tasks, just detach your current screen and issue the screen command again.
To see your screen processes, just type the following command:
[cmodiano@veelaora001 ~]$ screen -ls
There are screens on:
21931.pts-1.veelaora001 (Detached)
10145.pts-1.veelaora001 (Detached)
2 Sockets in /var/run/screen/S-cmodiano.
Here I have 2 different terminal currently detached.
To reattach a screen when it is detached you can issue:
[cmodiano@veelaora001 ~]$ screen -r screen_pid
Where screen_pid is the process id of the screen when you have multiple screens (if you have only one screen the screen_pid is not needed).
Instead of the pid you can also use the name of your screen if you named it.
This pid can be found by using the screen -ls
command :
21931.pts-1.veelaora001 (Detached)
Log everything you do
Using the screen command you can log everything happens on your terminal in a file, to do that, once you have attached the right screen to your session, just use “Ctrl-a” and then “H“.
A file named screenlog.0 will be created in your home directory.
Share your terminal
Screen alows you to share your screen with someone else so he can see what you do and even type command in your terminal.
To do this the other person just have to login to the server with the same account and type:
[cmodiano@veelaora001 ~]$ screen -x screen_name
This is really an awesome feature.
You can find the complete manual of screen here
Thank you for reading
this is really use full…!! thanks For sharing 🙂
I just discovered it myself and I regret not having known earlier about it. This is why I wanted to share it.
Very good tips, Thank you Cyrille!
Cyrille, thank you very much for sharing your knowledge. Please know that you have been a blessing to me.
You’re most welcome, thank you for reading my blog.
See you !
Awsome! Thanks Cyrille !