シェル スクリプト内で ssh された osascript を正しく実行できません

シェル スクリプト内で ssh された osascript を正しく実行できません

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-down シェルスクリプト:

#!/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 にもまだ非常に興味があります。その構文は私にとって非常にわかりにくいです。

関連情報