Sunday 8 June 2014

Linux tool - screen

when you have an long running or important task, sometimes you have to pray that the tty session won't be timed out during the task. Now you can use a powerful Linux tool called screen to help you.

1. start an screen session:

stack@openstack:~$ screen -S mytest

2. run your test program in my test session:
stack@openstack:~$ cd /var/tmp/
stack@openstack:/var/tmp$ cat test.sh
#!/bin/bash
while true
do
echo "hello world"
sleep 1
done

the program will keep printing out 'hello world'

3. you can use CRTL+a d to exit the session
[detached from 2898.mytest]

4. quit the putty session

5.use putty to relogin the session and use 'screen –ls' to check the running sessions
stack@openstack:~$ screen -ls
There is a screen on:
        2898.mytest     (08/06/14 20:41:59)     (Detached)
1 Socket in /var/run/screen/S-stack.

6. use screen –r mytest back to session

stack@openstack:~$ screen -r mytest
hello world
hello world
hello world
hello world
hello world
hello world
hello world

No comments:

Post a Comment