Kann das ssh-ed-Javascript nicht ordnungsgemäß in einem Shell-Skript ausführen

375
TYPKRFT

Ich habe ein ip-down-Skript in meinem Verzeichnis etc / ppp / erstellt. Im Wesentlichen versuche ich, bestimmte Programme / Server abzubrechen, wenn das VPN die Verbindung trennt, und eine Benachrichtigung auf einem anderen Computer über ssh anzuzeigen. Ich habe SSH-Schlüssel eingerichtet und der folgende Befehl funktioniert gut im Terminal, aber nicht im Skript:

ssh @ 'osascript -e "display notification \"The VPN has disconnected.\" with title \"Server\" sound name \"Pop\""' 

Alles andere im Skript funktioniert. Mein vollständiges Skript unten:

#!/bin/sh  killall someApp1 killall someApp2 killall someApp3 killall someApp4 ssh @ 'osascript -e "display notification \"The VPN has disconnected.\" with title \"Server\" sound name \"Pop\""' vpn-connect & 

Nebenbemerkung: Ich habe versucht, den gesamten Torrent-Verkehr auf en0 (Ethernet auf diesem Gerät) mit pf.conf zu blockieren, aber wenn ich blockieren würde, würde ich mich nicht mit meinem vpn verbinden lassen. Ich war mir nicht sicher, wie ich das zulassen sollte. Ich konnte ssh, https, Bildschirmfreigabe usw. zulassen. Alle Informationen dazu wären auch cool.

0

1 Antwort auf die Frage

0
TYPKRFT

Not an answer, but a work around.

Context: I have an older Macbook which I use as a headless Plex sever. I would like to keep it connected to VPN pretty much always. I would also like notifications when it connects and disconnects.

I ended up creating a event handling app. Then I used Apple Remote Events to call it and pass in arguments. After the arguments are passed and the event handler runs I tell the application to quit. This keeps it from just idling in the background. Lastly, I hid my notification from the dock by editing the plist. The reason I created a handler app instead of just using Finder to display the notification is because I wanted to have a customized icon for my notification.

Code for the Notification Helper (Event Handler):

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 script:

#!/bin/sh # kill applications killall someApp1 killall someApp2 killall someApp3 killall someApp4 # Open Notification Helper osascript <<EOF set remoteMachine to "eppc://:@" 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://:@" 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 & 

For those who don't know an ip-down script goes into you /etc/ppp/ directory and runs when the VPN is disconnected. You can also make an ip-up script, which runs when you connect to your VPN. My ip-up just turns on all my services and then sends me a notification letting me know the VPN is backup.

Comments, suggestions are appreciated. Still interested in understand why this would work, as it I have another script which notifies me when x happens from another program via ssh. Also still very interested in pf.conf. The syntax for it is very confusing to me.