테스트를 통해 ssh 실패자가 누구인지 확인하는 방법

테스트를 통해 ssh 실패자가 누구인지 확인하는 방법

SSH를 통해 몇 가지 테스트를 하고 싶다고 가정해 보겠습니다.

ssh 18.23.24.2 2>/dev/null "smartctl -a /dev/sdb -q silent"

echo $?
1

이 경우 종료 코드 1이 표시됩니다.

문제가 ssh 또는 smartctl 명령과 관련되어 있는지 확인하는 방법은 무엇입니까?

답변1

맨페이지에서:

EXIT STATUS
     ssh exits with the exit status of the remote command or with 255 if an error occurred.

ssh 명령에 오류가 발생하면 255를 반환하고, 그렇지 않으면 원격 명령의 종료 상태를 반환합니다.

예:

$ ssh [email protected]
ssh: Could not resolve hostname not.exists: Name or service not known
$ echo $?
255

smartctl귀하의 경우 1은 명령의 종료 상태가 아니라ssh


편집하다:

smartctl 종료 상태:

EXIT STATUS
       The  exit  statuses  of  smartctl  are  defined by a bitmask.  If all is well with the disk, the exit status (return value) of smartctl is 0 (all bits turned off).  If a problem occurs, or an error,
       potential error, or fault is detected, then a non-zero status is returned.  In this case, the eight different bits in the exit status have the following meanings for ATA disks; some of these  values
       may also be returned for SCSI disks.

       Bit 0: Command line did not parse.

       Bit 1: Device open failed, device did not return an IDENTIFY DEVICE structure, or device is in a low-power mode (see '-n' option above).

       Bit 2: Some SMART or other ATA command to the disk failed, or there was a checksum error in a SMART data structure (see '-b' option above).

       Bit 3: SMART status check returned "DISK FAILING".

       Bit 4: We found prefail Attributes <= threshold.

       Bit 5: SMART status check returned "DISK OK" but we found that some (usage or prefail) Attributes have been <= threshold at some time in the past.

       Bit 6: The device error log contains records of errors.

       Bit 7: The device self-test log contains records of errors.  [ATA only] Failed self-tests outdated by a newer successful extended self-test are ignored.

smartctl의 종료 상태 1은 1=2^0이므로 비트 0이 켜져 있으므로 명령줄을 구문 분석할 수 없음을 의미합니다.

답변2

많은 프로세스가 동일한 값을 사용하기 때문에 이 값을 결정하는 것은 어렵습니다.

% ssh 2>/dev/null localhost 'exit 255' ; echo $?
255
% ssh 2>/dev/null nopelocalhost 'exit 0' ; echo $?
255

경험적 방법을 사용하면 공통 종료 코드를 기반으로 어떤 코드가 어떤 프로그램에서 나오는지 추측할 수 있습니다. 이는 관련된 항목이 겹치거나 예상치 못한 일이 발생하지 않는 한 대부분 정확합니다. 표준 오류는 사용 가능하거나 사용 가능하지 않을 수 있으며, 종료 코드는 프로그램 종료 방법에 따라 변경될 수 있습니다.

% ssh localhost ./segfault ; echo $?
255
% ./segfault ; echo $?
zsh: bus error  ./segfault
138
% 

$?따라서 그것이 어디서 왔는지 추측하는 것은 덜 신뢰할 수 있습니다. 대신, 종료 상태 단어가 제공하는 것보다 더 많은 정보를 전달하는 프로토콜을 설계하는 것이 더 나은 옵션일 수 있습니다. 예를 들면 $?원격 명령이 실행되는 방법을 결정하는 것 이상을 전달하는 Nagios 또는 Ansible이 있습니다. 이는 smartctl실행 방법(또는 segfaults 또는...) 에 따라 한 줄의 텍스트만큼 간단할 수도 있고 stdout, 오류, 종료 상태 단어 및 기타 메타데이터가 포함된 JSON 구조와 같이 더 복잡할 수도 있습니다. 따라서 smartctl직접 실행하는 대신 smartctl출력을 실행 및 구문 분석하고 다른 쪽 끝에서 해당 출력을 수집하는 래퍼를 호출합니다 ssh. 출력을 사용할 수 없으면 ssh래퍼에 문제가 있는 것입니다.

관련 정보