netstat 출력의 언어

netstat 출력의 언어

여기 에 의존하는 프로그램이 있습니다 netstat.netstat -apn

다음은 정상적인 출력의 예입니다.

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -

내 고객 중 한 명은 다른 결과를 가지고 있습니다(예:).

Proto Recv-Q Send-Q Endereço Local          Endereço Remoto         Estado      PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               OUÇA       -

netstat변경된 출력 (예: 클라이언트 출력)을 사용하여 소프트웨어를 테스트하고 싶습니다 .

그래서 질문은: netstat클라이언트가 받는 오류를 재현할 수 있도록 출력 언어를 어떻게 변경해야 합니까?

언어 변경을 사용해 보았지만 export LANG=pt_PT출력이 변경되지 않습니다.

답변1

먼저, 컴퓨터에 필요한 지역 설정이 지정되어 있는지 확인해야 합니다. 를 사용하여 사용 가능한 로케일을 볼 수 있습니다 locale -a. 예를 들어 내 시스템에서는 다음과 같습니다.

$ locale -a
C
C.UTF-8
el_GR.utf8
en_US.utf8
fr_FR.utf8
POSIX

위에서 볼 수 있듯이 포르투갈어 로케일이 없습니다. 내 Debian에서는 sudo dpkg-reconfigure locales관련 로캘을 실행하고 선택하여 만들 수 있습니다.

패키지 구성

 ┌──────────────────────────┤ Configuring locales ├──────────────────────────┐  
 │ Locales are a framework to switch between multiple languages and allow    │  
 │ users to use their language, country, characters, collation order, etc.   │  
 │                                                                           │  
 │ Please choose which locales to generate. UTF-8 locales should be chosen   │  
 │ by default, particularly for new installations. Other character sets may  │  
 │ be useful for backwards compatibility with older systems and software.    │  
 │                                                                           │  
 │ Locales to be generated:                                                  │  
 │                                                                           │  
 │    [ ] pt_BR.UTF-8 UTF-8                                              ↑   │  
 │    [ ] pt_PT ISO-8859-1                                               ▒   │  
 │    [*] pt_PT.UTF-8 UTF-8                                              ▮   │  
 │    [ ] pt_PT@euro ISO-8859-15                                         ▒   │  
 │    [ ] quz_PE UTF-8                                                   ↓   │  
 │                                                                           │  
 │                                                                           │  
 │                    <Ok>                        <Cancel>                   │  
 │                                                                           │  
 └───────────────────────────────────────────────────────────────────────────┘  

을 클릭하면 다음 Enter이 표시됩니다.

$ sudo dpkg-reconfigure locales
Generating locales (this might take a while)...
  el_GR.UTF-8... done
  en_US.UTF-8... done
  fr_FR.UTF-8... done
  pt_PT.UTF-8... done
Generation complete.

Debian 기반 배포판을 사용하지 않는 경우 이 작업을 수동으로 수행해야 합니다.

  1. 에 관련 로캘 이름을 추가합니다 /etc/locale.gen. 예:

    pt_PT.UTF-8 UTF-8
    
  2. 달리기locale-gen

dpkg-reconfigre locales위의 단계(수동 방법 또는 별도의 방법 ) 를 거친 후 locale -a포르투갈어 로캘도 나열됩니다.

$ locale -a
C
C.UTF-8
el_GR.utf8
en_US.utf8
fr_FR.utf8
POSIX
pt_PT.utf8

이제 출력의 표시 언어를 선택할 수 있습니다.

$ LC_ALL=el_GR.utf8 date
Τετ 14 Οκτ 2015 12:34:28 μμ EEST
$ LC_ALL=fr_FR.utf8 date
mercredi 14 octobre 2015, 12:35:07 (UTC+0300)
$ LC_ALL=pt_PT.utf8 date
Qua Out 14 12:35:11 EEST 2015

그러나 특정 프로그램이 선택한 로케일로 출력을 인쇄할 수 있는지 여부는 해당 프로그램이 번역되었는지 여부, 관련 .mo번역 파일이 소프트웨어 패키지와 함께 제공되는지 여부에 따라 달라집니다. 의 경우에는 netstat입니다 /usr/share/locale/${LANG%_*}/LC_MESSAGES/net-tools.mo. 내 데비안에는 프랑스어 로캘이 있지만 포르투갈어 로캘에는 없습니다:

$ ls /usr/share/locale/{fr,pt}/LC_MESSAGES/net*
ls: cannot access /usr/share/locale/pt/LC_MESSAGES/net*: No such file or directory
/usr/share/locale/fr/LC_MESSAGES/net-tools.mo

이것이 제가 netstat프랑스어로 뛸 수 있는 이유입니다.

$ LC_ALL=fr_FR.utf8 netstat -apn | head -n2
(Tous les processus ne peuvent être identifiés, les infos sur les processus
non possédés ne seront pas affichées, vous devez être root pour les voir toutes.)
Connexions Internet actives (serveurs et établies)
Proto Recv-Q Send-Q Adresse locale          Adresse distante        Etat        PID/Program name

하지만 포르투갈어에서는 그렇지 않습니다.

$ LC_ALL=pt_PT.utf8 netstat -apn | head -n2
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

답변2

선택한 언어에 대한 언어 팩을 설치해야 합니다. 그렇지 않으면 텍스트 번역 유틸리티(문자 받기GNU 시스템에서는 메시지를 선택한 언어로 번역할 수 없습니다.

$ strace -fe trace=open sh -c 'LANGUAGE=fr_FR.utf8 netstat -tnlp'
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
Process 14847 attached
[pid 14847] open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
[pid 14847] open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
[pid 14847] open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
[pid 14847] open("/proc/3690/cmdline", O_RDONLY) = 5
[pid 14847] open("/proc/8579/cmdline", O_RDONLY) = 5
[pid 14847] open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
[pid 14847] open("/usr/share/locale/fr_FR.utf8/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 14847] open("/usr/share/locale/fr_FR/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 14847] open("/usr/share/locale/fr.utf8/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 14847] open("/usr/share/locale/fr/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 14847] open("/usr/share/locale-langpack/fr_FR.utf8/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 14847] open("/usr/share/locale-langpack/fr_FR/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 14847] open("/usr/share/locale-langpack/fr.utf8/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 14847] open("/usr/share/locale-langpack/fr/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
....
[pid 14847] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=14847, si_status=0, si_utime=0, si_stime=2} ---
+++ exited with 0 +++

프로세스가 자신이 속한 패키지 의 번역된 텍스트를 /usr/share/locale찾아 /usr/share/locale-langpack가져오려고 시도하는 것을 볼 수 있습니다 .net-toolsnetstat

이제 언어팩을 설치하면 됩니다. Ubuntu 시스템의 경우:

sudo apt-get install language-pack-fr

다른 시스템에서는 적어도 Debian 및 Centos에서는 패키지의 관련 언어 팩이 패키지 자체에 포함될 수 있습니다.

$ apt-file search /usr/share/locale/fr/LC_MESSAGES/net-tools.mo
net-tools: /usr/share/locale/fr/LC_MESSAGES/net-tools.mo

(Centos에서는 사용할 수 있습니다 yum whatprovides)

그 다음에:

$ strace -fe trace=open sh -c 'LANGUAGE=fr_FR.utf8 netstat -tnlp'
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
Process 15155 attached
[pid 15155] open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
[pid 15155] open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
[pid 15155] open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
[pid 15155] open("/proc/3690/cmdline", O_RDONLY) = 5
[pid 15155] open("/proc/8579/cmdline", O_RDONLY) = 5
[pid 15155] open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
[pid 15155] open("/usr/share/locale/fr_FR.utf8/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 15155] open("/usr/share/locale/fr_FR/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 15155] open("/usr/share/locale/fr.utf8/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 15155] open("/usr/share/locale/fr/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 15155] open("/usr/share/locale-langpack/fr_FR.utf8/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 15155] open("/usr/share/locale-langpack/fr_FR/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 15155] open("/usr/share/locale-langpack/fr.utf8/LC_MESSAGES/net-tools.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
[pid 15155] open("/usr/share/locale-langpack/fr/LC_MESSAGES/net-tools.mo", O_RDONLY) = 3
[pid 15155] open("/usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache", O_RDONLY) = 3
(Tous les processus ne peuvent être identifiés, les infos sur les processus
non possédés ne seront pas affichées, vous devez être root pour les voir toutes.)
Connexions Internet actives (seulement serveurs)
Proto Recv-Q Send-Q Adresse locale          Adresse distante        Etat       PID/Program name
....
[pid 15155] +++ exited with 0 +++
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=15155, si_status=0, si_utime=0, si_stime=3} ---
+++ exited with 0 +++

/usr/share/locale-langpack/fr/LC_MESSAGES/net-tools.mogettext()메시지가 성공적으로 번역되었습니다 .

vi_VN를 설치하더라도 모든 단어가 번역될 수 있는 것은 아닙니다 language-pack-vi.


LC_ALL다음을 사용하여 다른 모든 현지화 설정을 재정의 해야 합니다.GNU 시스템의 LANGUAGE 제외위와 같이.

관련 정보