Search This Blog

Showing posts with label screen. Show all posts
Showing posts with label screen. Show all posts

Thursday, May 19, 2011

Screen trick how to simultaneously monitor network traffic and disk activity and processes in Linux

As a system administrator sooner than later you will discover the 'screen' command. It is very powerful tool that allows you practically do anything with your (black) terminal screen or run commands in background for you.

The tools we will use for monitoring:
- htop is a top like process monitoring tool for text consoles
- nethogs is a network monitoring tool (needs root privileges!)
- iotop is a disk I/O monitoring tool

To start a single screen session, divided in 3 vertical smaller screens, each running its own monitoring program try this recipe:

# cat <<END >/tmp/myscreen.cfg
startup_message off
screen -t top htop
split
focus
screen -t nethogs  nethogs wlan0
split
focus
screen -t iotop iotop
END

# screen -c /tmp/myscreen.cfg

References:
Top 10 Awesome Linux Screen Tricks

Sunday, May 1, 2011

Howto capture and record the console screen output to a file on disk

The basic of capturing a data to a file require simple redirection or using of 'tee' program for example.

Examples:

$ ls -la > /var/tmp/output.ls.txt
$ ls -la | tee /var/tmp/output.ls.txt

But sometimes programs can be interactive or we simply want to capture all our session without to worry to redirect the stdout to a file.

The solution is to use the 'screen' tool.

Example #1: Screen basic usage

# to start the session with a name 'example' run
$screen -h
$screen -S example

# to leave the screen session type: CONTROL-a d
# you are placed back in the original shell

# to reattach to the created session
$ screen -ls
$ screen -r example

Example #1: Enable screen logging

The options '-L' instruct screen to create a log file that will capture all the commands output in the screen session.

$ screen -S logexample -L

# inside the screen session
$ echo 'some output'

# to leave the screen session type: CONTROL-a d

# this is the default log file for screen
$ ls -la screenlog.0

$ cat screenlog.0