
내 etc/ppp/ 디렉토리에 ip-down 스크립트를 만들었습니다. 본질적으로 VPN 연결이 끊어지면 특정 프로그램/서버를 종료한 다음 SSH를 통해 다른 컴퓨터에 알림을 표시하려고 합니다. SSH 키를 설정했는데 다음 명령이 터미널에서는 제대로 작동하지만 스크립트 내부에서는 작동하지 않습니다.
ssh {userName}@{address} 'osascript -e "display notification \"The VPN has disconnected.\" with title \"Server\" sound name \"Pop\""'
스크립트의 다른 모든 것은 작동합니다. 내 전체 스크립트는 다음과 같습니다.
#!/bin/sh
killall someApp1
killall someApp2
killall someApp3
killall someApp4
ssh {userName}@{address} 'osascript -e "display notification \"The VPN has disconnected.\" with title \"Server\" sound name \"Pop\""'
vpn-connect &
참고 사항: pf.conf를 사용하여 en0(이 장치의 이더넷)에서 모든 토렌트 트래픽을 차단하려고 했지만 차단하면 VPN에 연결할 수 없습니다. 나는 그것을 어떻게 허용해야 할지 확신하지 못했습니다. SSH, https, 화면 공유 등을 허용할 수 있었습니다. 이에 대한 정보도 있으면 좋을 것 같습니다.
답변1
답변은 아니지만 해결 방법이 있습니다.
컨텍스트: 헤드리스 Plex 서버로 사용하는 구형 Macbook이 있습니다. 나는 거의 항상 VPN에 연결된 상태를 유지하고 싶습니다. 연결되거나 연결이 끊어질 때에도 알림을 받고 싶습니다.
결국 이벤트 처리 앱을 만들었습니다. 그런 다음 Apple Remote Events를 사용하여 이를 호출하고 인수를 전달했습니다. 인수가 전달되고 이벤트 핸들러가 실행된 후 애플리케이션을 종료하도록 지시합니다. 이렇게 하면 백그라운드에서 유휴 상태가 되는 것을 방지할 수 있습니다. 마지막으로 plist를 편집하여 도크에서 알림을 숨겼습니다. 알림을 표시하기 위해 Finder를 사용하는 대신 핸들러 앱을 만든 이유는 알림에 대한 사용자 정의 아이콘을 갖고 싶었기 때문입니다.
알림 도우미(이벤트 처리기) 코드:
on run
idle
end run
on idle argv
try
eHandler(item 1 of argv, item 2 of argv, item 3 of argv)
end try
end idle
on eHandler(message, title, soundName)
set theMessage to message as string
set theTitle to title as string
set theSoundName to the soundName as string
display notification theMessage with title theTitle sound name theSoundName
end eHandler
IP-다운 쉘 스크립트:
#!/bin/sh
# kill applications
killall someApp1
killall someApp2
killall someApp3
killall someApp4
# Open Notification Helper
osascript <<EOF
set remoteMachine to "eppc://{userName}:{password}@{address}"
tell application "Finder" of machine remoteMachine
open ("/Applications/Notification Helper.app" as POSIX file)
end tell
EOF
# Sends Notification Helper arguments
osascript <<EOF
tell application "Notification Helper" of machine "eppc://{userName}:{password}@{address}"
TestHandler("The VPN has been disconnected.", "Media Server", "Pop")
quit
end tell
EOF
# Calls applescript which reconnects my VPN.
# The & Stops script from waiting to end
vpn-connect &
ip-down 스크립트를 모르는 사람들을 위해 /etc/ppp/ 디렉토리에 들어가 VPN 연결이 끊어지면 실행됩니다. VPN에 연결할 때 실행되는 ip-up 스크립트를 만들 수도 있습니다. 내 IP-Up은 내 모든 서비스를 켜고 VPN이 백업되었음을 알리는 알림을 보냅니다.
의견, 제안에 감사드립니다. ssh를 통해 다른 프로그램에서 x가 발생할 때 알려주는 또 다른 스크립트가 있기 때문에 이것이 왜 작동하는지 이해하는 데 여전히 관심이 있습니다. 또한 여전히 pf.conf에 관심이 많습니다. 이에 대한 구문은 나에게 매우 혼란스럽습니다.