Redirect stderr to /dev/null so that ignore prints of standard errors in terminal prompt.


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)
  • Redirect


Terms

What is /dev/null?

  • /dev/null: Device file that discards all data written to it but reports that the write operation succeeded.
  • You can ignore standard error on screen when you write stderr to /dev/null.

What is redirect?

  • Redirect('>'): Redirect standard streams to user-specified locations like file or other stream.
  • Reference: Redirection (computing)


Usage example

Ignore stderr in find command

  • It prints Permission denied as stderr
$ find / | grep neutron
find: ‘/run/docker’: Permission denied
find: ‘/run/containerd’: Permission denied
find: ‘/run/lxcfs’: Permission denied
find: ‘/run/sudo’: Permission denied
find: ‘/run/log/journal/50739525d1fb4eac9e863478fb990fed’: Permission denied
find: ‘/run/lvm’: Permission denied
  • After redirect stderr to /dev/null, there is no Permission denied
  • 2 represents stderr
find / 2> /dev/null | grep neutron
/home/twpower/test/neutron_patched
/home/twpower/test/neutron_patched/LICENSE
/home/twpower/test/neutron_patched/.gitignore
/home/twpower/test/neutron_patched/bin
...


Reference

iperf3를 이용해 두 컴퓨터간 네트워크 성능을 측정해보자.


환경

  • Linux 기반 시스템
  • Bash shell(/bin/bash)
  • NIC 장치와 스위치 그리고 서브넷의 개념
  • ip 명령어에 대한 기본 사용법


iperf3 명령어

iperf3 명령어란?

iperf3 -s [ options ]
iperf3 -c server [ options ]
  • iperf3: 두 컴퓨터간 네트워크 성능을 측정해주는 도구입니다.
  • iperf2 그리고 iperf도 있습니다.


설치법

  • CentOS
sudo yum install iperf3 -y
  • Ubuntu
sudo apt-get install iperf3 -y


사용법

  • 두개의 서버중에 하나를 서버 다른 하나를 클라이언트로 정하고 각각 아래 명령어를 사용해주시면 됩니다.
  • iperf3이 사용하는 port는 두 컴퓨터 다 열려있어야 합니다.
  • port는 5201번 포트를 사용합니다.

서버 컴퓨터

  • 다음 명령어 실행
iperf3 -s

클라이언트 컴퓨터

  • 다음 명령어 실행
  • IP ADDRESS에는 성능을 측정하고 싶은 다른 컴퓨터의 IP주소를 넣어주며 위에서 실행한 서버의 IP를 넣어주시면 됩니다.
iperf3 -c [IP ADDRESS]


예제

사용할 컴퓨터 정보

  • Server
$ ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:3e:6c:4f:da:2b brd ff:ff:ff:ff:ff:ff
    inet 10.136.105.252/16 brd 10.136.255.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::503e:6cff:fe4f:da2b/64 scope link
       valid_lft forever preferred_lft forever
  • Client
$ ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 9e:79:07:2a:26:e3 brd ff:ff:ff:ff:ff:ff
    inet 10.136.107.214/16 brd 10.136.255.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::9c79:7ff:fe2a:26e3/64 scope link
       valid_lft forever preferred_lft forever

서버에서 실행

# Update package list
$ sudo apt-get update -y

# Install package
$ sudo apt-get install iperf3 -y

# Run iperf3 server
$ iperf3 -s

클라이언트에서 실행

# Update package list
$ sudo apt-get update -y

# Install package
$ sudo apt-get install iperf3 -y

# Run iperf3 server
$ iperf3 -c 10.136.105.252

결과

  • Server
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 10.136.107.214, port 36216
[  5] local 10.136.105.252 port 5201 connected to 10.136.107.214 port 36218
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec   251 MBytes  2.11 Gbits/sec
[  5]   1.00-2.00   sec   238 MBytes  1.99 Gbits/sec
[  5]   2.00-3.00   sec   236 MBytes  1.98 Gbits/sec
[  5]   3.00-4.00   sec   236 MBytes  1.98 Gbits/sec
[  5]   4.00-5.00   sec   241 MBytes  2.02 Gbits/sec
[  5]   5.00-6.00   sec   237 MBytes  1.99 Gbits/sec
[  5]   6.00-7.00   sec   236 MBytes  1.98 Gbits/sec
[  5]   7.00-8.00   sec   242 MBytes  2.03 Gbits/sec
[  5]   8.00-9.00   sec   238 MBytes  2.00 Gbits/sec
[  5]   9.00-10.00  sec   237 MBytes  1.99 Gbits/sec
[  5]  10.00-10.04  sec  10.2 MBytes  2.07 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-10.04  sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-10.04  sec  2.35 GBytes  2.01 Gbits/sec                  receiver
  • Client
Connecting to host 10.136.105.252, port 5201
[  4] local 10.136.107.214 port 36218 connected to 10.136.105.252 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   262 MBytes  2.20 Gbits/sec  16168   97.6 KBytes
[  4]   1.00-2.00   sec   239 MBytes  2.00 Gbits/sec  16140    451 KBytes
[  4]   2.00-3.00   sec   240 MBytes  2.01 Gbits/sec  13883    136 KBytes
[  4]   3.00-4.00   sec   238 MBytes  2.00 Gbits/sec  11752    365 KBytes
[  4]   4.00-5.00   sec   238 MBytes  2.00 Gbits/sec  18333    297 KBytes
[  4]   5.00-6.00   sec   238 MBytes  1.99 Gbits/sec  19573    122 KBytes
[  4]   6.00-7.00   sec   238 MBytes  1.99 Gbits/sec  18483    115 KBytes
[  4]   7.00-8.00   sec   234 MBytes  1.96 Gbits/sec  17792    229 KBytes
[  4]   8.00-9.00   sec   241 MBytes  2.02 Gbits/sec  15119   1.20 MBytes
[  4]   9.00-10.00  sec   239 MBytes  2.00 Gbits/sec  23006   93.3 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  2.35 GBytes  2.02 Gbits/sec  170249             sender
[  4]   0.00-10.00  sec  2.35 GBytes  2.01 Gbits/sec                  receiver

iperf Done.


참고자료

Measure network performance using iperf3


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)
  • Concept of NIC device, switch and subnet
  • Basic usage of ip command


iperf3 command

What is iperf3?

iperf3 -s [ options ]
iperf3 -c server [ options ]
  • iperf3: Measure network performance of two computers.
  • There are also iperf2 and iperf.


Installation

  • CentOS
sudo yum install iperf3 -y
  • Ubuntu
sudo apt-get install iperf3 -y


Usage

  • In two computers, decide one is server and the other is client. After decide each of it, run each command like below.
  • Port should be opened in each computer.
  • iperf3 use 5201 port.

Server

  • Use below command
iperf3 -s

Client

  • Use below command
  • Put IP address of server to IP ADDRESS which you want to measure performance. Put above iperf3 running server’s IP.
iperf3 -c [IP ADDRESS]


Example

Computer network information

  • Server
$ ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:3e:6c:4f:da:2b brd ff:ff:ff:ff:ff:ff
    inet 10.136.105.252/16 brd 10.136.255.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::503e:6cff:fe4f:da2b/64 scope link
       valid_lft forever preferred_lft forever
  • Client
$ ip addr show eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 9e:79:07:2a:26:e3 brd ff:ff:ff:ff:ff:ff
    inet 10.136.107.214/16 brd 10.136.255.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::9c79:7ff:fe2a:26e3/64 scope link
       valid_lft forever preferred_lft forever

Run in server

# Update package list
$ sudo apt-get update -y

# Install package
$ sudo apt-get install iperf3 -y

# Run iperf3 server
$ iperf3 -s

Run in client

# Update package list
$ sudo apt-get update -y

# Install package
$ sudo apt-get install iperf3 -y

# Run iperf3 server
$ iperf3 -c 10.136.105.252

Result

  • Server
-----------------------------------------------------------
Server listening on 5201
-----------------------------------------------------------
Accepted connection from 10.136.107.214, port 36216
[  5] local 10.136.105.252 port 5201 connected to 10.136.107.214 port 36218
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-1.00   sec   251 MBytes  2.11 Gbits/sec
[  5]   1.00-2.00   sec   238 MBytes  1.99 Gbits/sec
[  5]   2.00-3.00   sec   236 MBytes  1.98 Gbits/sec
[  5]   3.00-4.00   sec   236 MBytes  1.98 Gbits/sec
[  5]   4.00-5.00   sec   241 MBytes  2.02 Gbits/sec
[  5]   5.00-6.00   sec   237 MBytes  1.99 Gbits/sec
[  5]   6.00-7.00   sec   236 MBytes  1.98 Gbits/sec
[  5]   7.00-8.00   sec   242 MBytes  2.03 Gbits/sec
[  5]   8.00-9.00   sec   238 MBytes  2.00 Gbits/sec
[  5]   9.00-10.00  sec   237 MBytes  1.99 Gbits/sec
[  5]  10.00-10.04  sec  10.2 MBytes  2.07 Gbits/sec
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth
[  5]   0.00-10.04  sec  0.00 Bytes  0.00 bits/sec                  sender
[  5]   0.00-10.04  sec  2.35 GBytes  2.01 Gbits/sec                  receiver
  • Client
Connecting to host 10.136.105.252, port 5201
[  4] local 10.136.107.214 port 36218 connected to 10.136.105.252 port 5201
[ ID] Interval           Transfer     Bandwidth       Retr  Cwnd
[  4]   0.00-1.00   sec   262 MBytes  2.20 Gbits/sec  16168   97.6 KBytes
[  4]   1.00-2.00   sec   239 MBytes  2.00 Gbits/sec  16140    451 KBytes
[  4]   2.00-3.00   sec   240 MBytes  2.01 Gbits/sec  13883    136 KBytes
[  4]   3.00-4.00   sec   238 MBytes  2.00 Gbits/sec  11752    365 KBytes
[  4]   4.00-5.00   sec   238 MBytes  2.00 Gbits/sec  18333    297 KBytes
[  4]   5.00-6.00   sec   238 MBytes  1.99 Gbits/sec  19573    122 KBytes
[  4]   6.00-7.00   sec   238 MBytes  1.99 Gbits/sec  18483    115 KBytes
[  4]   7.00-8.00   sec   234 MBytes  1.96 Gbits/sec  17792    229 KBytes
[  4]   8.00-9.00   sec   241 MBytes  2.02 Gbits/sec  15119   1.20 MBytes
[  4]   9.00-10.00  sec   239 MBytes  2.00 Gbits/sec  23006   93.3 KBytes
- - - - - - - - - - - - - - - - - - - - - - - - -
[ ID] Interval           Transfer     Bandwidth       Retr
[  4]   0.00-10.00  sec  2.35 GBytes  2.02 Gbits/sec  170249             sender
[  4]   0.00-10.00  sec  2.35 GBytes  2.01 Gbits/sec                  receiver

iperf Done.


Reference

grep과 옵션을 이용해 현재 및 하위 폴더 파일들에서 문자열 혹은 내용을 찾아보자.


환경

  • Linux 기반 시스템
  • Bash shell(/bin/bash)


grep 명령어

grep 명령어란?

grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
  • grep: 어떤 주어진 패턴에 맞는 문자열을 출력해주는 명령어입니다. 다양한 옵션과 방법으로 많이 사용합니다.


r과 n옵션으로 하위 파일들 내용 모두 검색하기

사용법

  • 찾고자하는 폴더 또는 경로에서 아래 명령어를 사용
grep -rn [PATTERN]

기본 예제

  • -r: 하위 폴더에 있는 파일까지 모두 검색해주는 옵션
  • -n: 해당 패턴이 일치하는 줄도 같이 출력해주는 옵션
$ grep -rn "abc def hij"
test/test_ascii.txt:2:abc def hij

여러 패턴 찾기

  • -e: 여러 패턴을 찾을 수 있게 해주는 옵션 => OR
$ grep -rn -e "send" -e "test"
.gitignore:41:# Unit test / coverage reports
.gitignore:47:nosetests.xml
.gitignore:51:.pytest_cache/
smc_on_in_text:13:0 10 17 * * python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
smc_on_in_text:14:50 10 * * 3 python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
...

특정 패턴 제외하기

  • -v: 특정 패턴을 제외해주는 옵션
$ grep -rn -e "send" -e "test" | grep -v ".gitignore"
smc_on_in_text:13:0 10 17 * * python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
smc_on_in_text:14:50 10 * * 3 python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
reminder.py:6:def sendMail(sender_email, receiver_email, app_password ,msg):
reminder.py:9:    smtp.login(sender_email, app_password)
...

특정 폴더들 지정하기

  • 다음처럼 특정 패턴들과 함께 폴더들을 지정할 수 있습니다.
$ grep -rn -e "def sednMail" -e "with open" MailReminder ./test/neutron
MailReminder/reminder.py:19:with open('/home/twpower/MailReminder/account.json') as account_json_file:
./test/neutron/doc/source/contributor/internals/quality_of_service.rst:349:combination with openflow rules.
...


참고자료

Find contents or string in current or subfolder files using grep and its option


Environment and Prerequisite

  • Linux base system
  • Bash shell(/bin/bash)


grep command

What is grep?

grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]
  • grep: Print lines matching a pattern. It can be used with other commands and various options.


Find contents in all subfolder files using r and n option

Usage

  • Use below command in folder or directory where you want to find
grep -rn [PATTERN]

Basic example

  • -r: Find all subdirectory files recursively
  • -n: Print matching string with line number
$ grep -rn "abc def hij"
test/test_ascii.txt:2:abc def hij

Find many of patterns

  • -e: You can find more than one pattern => OR
$ grep -rn -e "send" -e "test"
.gitignore:41:# Unit test / coverage reports
.gitignore:47:nosetests.xml
.gitignore:51:.pytest_cache/
smc_on_in_text:13:0 10 17 * * python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
smc_on_in_text:14:50 10 * * 3 python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
...

Exclude specific pattern

  • -v: Exclude specific pattern
$ grep -rn -e "send" -e "test" | grep -v ".gitignore"
smc_on_in_text:13:0 10 17 * * python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
smc_on_in_text:14:50 10 * * 3 python /home/twpower/MailReminder/reminder.py >> /home/twpower/test.txt
reminder.py:6:def sendMail(sender_email, receiver_email, app_password ,msg):
reminder.py:9:    smtp.login(sender_email, app_password)
...

Give specific directory

  • You can give specific directories as arguments.
$ grep -rn -e "def sednMail" -e "with open" MailReminder ./test/neutron
MailReminder/reminder.py:19:with open('/home/twpower/MailReminder/account.json') as account_json_file:
./test/neutron/doc/source/contributor/internals/quality_of_service.rst:349:combination with openflow rules.
...


Reference