TCL 스크립트에서 이 시점에 특정 오류 코드를 어떻게 반환할 수 있나요?

TCL 스크립트에서 이 시점에 특정 오류 코드를 어떻게 반환할 수 있나요?

내 DNS 서버에 구성 파일을 업로드하기 위해 scp 명령을 실행하는 TCL 예상 스크립트가 있습니다.

#!/usr/bin/expect -f

set config "~/dnsmasq.conf"

spawn /usr/bin/scp "$config" [email protected]:/etc/dnsmasq.conf

expect {
    -re ".*yes.*no.*" {
        exp_send "yes\r"
        exp_continue
    }
    -re ".*password.*" {
        exp_send "$password\r"
        expect {
            -re ".*denied.*" {
                exit 7
            }
        }
    }
}

scp 유틸리티를 찾을 수 없는 경우 특정 오류 코드를 반환하고 싶습니다. 현재 스크립트는 상태 1로 종료됩니다. 스크립트가 상태 7로 종료되면 액세스 거부 오류임을 알기 때문에 이를 처리할 수 있습니다. Apache 로그에 나타나는 오류는 다음과 같습니다.

couldn't execute "/usr/bin/scp": no such file or directory
    while executing
"spawn /usr/bin/scp "$config" [email protected]:/etc/dnsmasq.conf"

이 시점에서 오류 코드 5 등을 어떻게 반환할 수 있나요?

답변1

이를 수행하는 가장 좋은 방법은 존재하고 실행 가능한지 확인하는 것입니다.

if { ! ([file exists /usr/bin/scp] && [file executable /usr/bin/scp])} {
    puts stderr "/usr/bin/scp does not exist or is not executable"
    exit 7
}

spawn /usr/bin/scp ...

관련 정보