Question

I need to send growl notifications from a bash script, but I don't have the ability to install either the growlnotify command line tool, or the perl module that could do similar. I can write arbitrary bash scripts, and after doing a quick inventory of what is available on this linux machine, it seems I have netcat.

Can I send a growl notification in such a manner? I've been tinkering with something like this:

echo -ne "GNTP/1.0 NOTIFY NONE MD5:04cf1ad341ea8e51d7bb314424276c38.6162636465666768\r\nApplication-Name: test Notification-Name testtest Notification-Title: blah \r\n\r\n" | nc -v 127.0.0.1 23053

But it's unclear to me how the protocol actually works. I'm assuming that when clients subscribe to another computer, they're basically registering themselves to a list of computers for the server to connect to (over 23053), send a formatted message, maybe wait for a reply, and then disconnect. Since my bash script would contain the list (or more likely, accept the list as an argument) of machines to send to, this subscription step could be skippable (unless there are magic values I need to pass!).

I don't believe that I'm performing the hash correctly, or else I've not got the client machine set up to receive incoming notifications correctly.

What's missing here?

I get back the following error message when I run this or similar commands:

GNTP/1.0 -ERROR NONE
Error-Code: 400
Error-Description: Invalid key hash
Origin-Machine-Name: SOMETHING
Origin-Software-Name: Growl/Win
Origin-Software-Version: 2.0.9.1
Origin-Platform-Name: Microsoft Windows NT 6.1.7601 Service Pack 1
Origin-Platform-Version: 6.1.7601.65536
X-Message-Daemon: Growl/Win
X-Timestamp: 2/5/2013 11:54:28 AM
Was it helpful?

Solution 2

For network notifications, you need to use a password, which must be salted and hashed in a particular way. Additionally, the computer that will be sending notifications must also have first sent registration command with one or more notification types defined.

To do the password salting/hashing, you'd do something like this:

# Hexify the salt:
HEXSALT=`echo -n $SALT | xxd -p`

# Md5 the password+salt
KEYBASIS=`echo -n "$PASSWORD$SALT" | $MD5SUM`
KEYBASIS=${KEYBASIS:0:32}
KEY=`echo -n "$KEYBASIS" | xxd -r -p | $MD5SUM`
KEY=${KEY:0:32}

Note that the salt can be completely arbitrary (and can change, message to message), as long as it's at least 4 characters in size. Then, you build the registration message:

# Now we need to build the message string.
MESSAGE="GNTP/1.0 REGISTER NONE MD5:$KEY.$HEXSALT
Application-Name: My Application
Application-Icon: http://somesite.come/whatever.png
Notifications-Count: 2

Notification-Name: startup
Notification-Display-Name: Starting
Notification-Enabled: False

Notification-Name: downtime
Notification-Display-Name: Shutting Down
Notification-Enabled: True

"
MESSAGE=`echo -ne "$MESSAGE" | $UNIX2DOS`
echo "$MESSAGE"

In theory the icon can be sent in the message, I've never managed to get it to work. Icons should be at least 64x64 or they look weird in Growl for Windows, I've not checked with Growl for Mac or Apple's Notification Center. Then to send the message, something like:

echo "$MESSAGE" | nc -v $ipaddress 23053

Though you could probably eliminate netcat entirely and use bash's TCP facilities (/dev/tcp)... I just have never used that before, don't know how. Finally, to send a notice, you'd do this:

MESSAGE="GNTP/1.0 NOTIFY NONE MD5:$KEY.$HEXSALT
Application-Name: $APPLICATION
Notification-Name: $NAME
Notification-Title: $TITLE
Notification-Text: $TEXT
Notification-Sticky: $STICKY
Notification-Priority: $PRIORITY

"
MESSAGE=`echo -ne "$MESSAGE" | $UNIX2DOS`
echo "$MESSAGE"

App-name and Not-name have to match what was send in registration. Priority has to be between -2 and 2. "Sticky" is True/False.

OTHER TIPS

echo needs the -e flag to properly interpret the escaped characters \r and \n.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top