![ufw가 프로그래밍 방식으로 실행되고 있는지 확인하는 방법](https://rvso.com/image/1083748/ufw%EA%B0%80%20%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D%20%EB%B0%A9%EC%8B%9D%EC%9C%BC%EB%A1%9C%20%EC%8B%A4%ED%96%89%EB%90%98%EA%B3%A0%20%EC%9E%88%EB%8A%94%EC%A7%80%20%ED%99%95%EC%9D%B8%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
대부분의 서비스(예: privoxy)에는 서비스 상태를 얻는 깔끔한 방법이 있습니다.
ps -C [servicename]
그런 다음 종료 코드를 확인합니다 ($?)
. 0: 서비스가 실행 중이었습니다. 1: 실행 중이 아닙니다. ufw에서는 그렇지 않습니다(서비스로 인식되지 않습니까?). sudo service ufw status
ufw가 실행 중인지 여부에 관계없이 항상 0으로 종료됩니다 . ufw 상태를 확인하는 데 사용되는 명령의 종료 코드를 통해 프로그래밍 방식으로 ufw를 가져오는 제안이 있습니까?
답변1
에서 반환된 종료 코드는 항상 0이므로 상태 값만 입력 sudo ufw status
하면 됩니다 .grep
$ sudo ufw status
Status: inactive
$ sudo ufw status | grep -qw active
$ echo $?
1
-w
올바르게 작동하려면 다음 옵션을 사용해야 합니다 man grep
.
-w, --word-regexp
Select only those lines containing matches that form whole
words. The test is that the matching substring must either be
at the beginning of the line, or preceded by a non-word
constituent character. Similarly, it must be either at the end
of the line or followed by a non-word constituent character.
Word-constituent characters are letters, digits, and the
underscore.
-q
단지 자동 모드일 뿐이며 표준 출력에는 아무것도 기록되지 않습니다.
답변2
UFW 사용 상태를 확인하려면
sudo ufw status verbose
출력은 다음과 유사합니다.
my@machine:~$ sudo ufw status verbose
[sudo] password for youruser:
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing)
New profiles: skip