我已经在我的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,屏幕共享等。关于它的任何信息也很酷。
不是答案,而是解决方法。
上下文:我有一台较旧的Macbook,用作无头Plex服务器。我想几乎一直保持它与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-down shell脚本:
#!/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断开连接时运行的人。您还可以制作一个ip-up脚本,该脚本在您连接到VPN时运行。我的ip-up只会打开我的所有服务,然后向我发送通知,让我知道VPN已备份。
评论,建议表示赞赏。仍然有兴趣了解为什么它会起作用,因为它有另一个脚本,当通过ssh从另一个程序中发生x时会通知我。对pf.conf还是很感兴趣的。它的语法令我非常困惑。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句