
SSH를 사용하여 원격으로 디스크 공간을 추출하려면 다음 명령을 사용하고 있습니다. 하지만 아래와 같이 다른 모든 메시지 대신 출력을 저장하려고 합니다.
도움이 필요하세요? 아니면 대체 솔루션이 있나요?
ssh rajesh-server 'df -h /db* | cat' 2>&1
|-----------------------------------------------------------------|
| This system is for the use of authorized users only. |
| Individuals using this computer system without authority, or in |
| excess of their authority, are subject to having all of their |
| activities on this system monitored and recorded by system |
| personnel. |
| |
| In the course of monitoring individuals improperly using this |
| system, or in the course of system maintenance, the activities |
| of authorized users may also be monitored. |
| |
| Anyone using this system expressly consents to such monitoring |
| and is advised that if such monitoring reveals possible |
| evidence of criminal activity, system personnel may provide the |
| evidence of such monitoring to law enforcement officials. |
|-----------------------------------------------------------------|
Filesystem Size Used Avail Use% Mounted on
/dev/vx/dsk/xcv01_day/db01_day
200G 154G 44G 79% /db01_day
/dev/vx/dsk/xcvg01_day/db01_day
200G 154G 44G 79% /db01_day
/dev/vx/dsk/xcvg01_day/db01_day
200G 154G 44G 79% /db01_day
답변1
"상자"의 모든 텍스트는 명령이 아닌 로그인 스크립트에 의해 생성됩니다 df
. 로그인 메시지로 설정된 서버는 .hushlogin
홈 디렉토리에 호출된 파일이 있는 경우 해당 메시지 표시를 건너뛰는 경우가 많습니다. 먼저 해당 파일을 만들어 보십시오.
ssh rajesh-server "touch .hushlogin"
| cat
다음으로 명령줄에 또는 stderr 리디렉션이 필요하지 않습니다 . 대신 이것을 시도해 보세요:
ssh rajesh-server 'df -h /db*'
여전히 파일이 있는 메시지를 받으면 .hushlogin
출력을 구문 분석해야 합니다. 이렇게 하면 됩니다:
ssh rajesh-server 'df -h /db*' | sed '/^|/d'
이 sed
명령은 ssh 명령의 출력을 가져와 파이프 문자로 시작하는 모든 줄을 삭제하고 다른 모든 내용을 인쇄합니다.
이러한 종류의 작업을 위해 특별히 제작된 모니터링 도구 사용을 고려하고 싶을 수도 있습니다. 많은 것이 존재하며 일부는 다음과 같습니다.RRD도구프런트엔드. 내가 가장 좋아하는 것은선인장그리고무닌. 디스크(또는 네트워크 또는 기타) 사용량을 그래프로 표시하므로 시간이 지남에 따라 상황이 어떻게 변하는지 확인할 수 있습니다.
답변2
ssh rajesh-server 'df -h /db*' > file 2> /dev/null
서버의 잔해물을 에 보내는 동안 원격 df
출력을 에 보냅니다 .file
/dev/null