Created
October 9, 2012 21:45
-
-
Save drbobbeaty/3861655 to your computer and use it in GitHub Desktop.
Bash script to send stdin to a Campfire room using curl API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script takes stdin and sends it to the QuantumLead Campfire room as | |
# Canadarm. This can take an optional '-p' argument so that the stdin will | |
# be treated as a "paste" and go in as a fix-edwidth font paste. Otherwise, | |
# it'll appear as a simple proportional font "message" | |
# | |
# Let's make sure all the commands we need are accessible to us... | |
export PATH="/usr/local/bin:/usr/local/sbin:/usr/sbin:/sbin:$HOME/bin:$PATH" | |
# start with the AuthToken for Canadarm and the QuantumLead room | |
token="969baac86c42c23ff715f0000000000000000000:X" | |
room="511111" | |
# see if we have the option to treat it as a 'paste' | |
paste='' | |
for arg in "$@"; do | |
case "$arg" in | |
-p) | |
paste='<type>PasteMessage</type>' | |
;; | |
esac | |
done | |
# grab all of stdin - unless there is nothing, and put in something | |
body=$(cat) | |
if [ ${#body} -eq 0 ]; then | |
body='empty' | |
fi | |
# now we can build up the curl command and ship it out | |
msg="<message><body>${body}</body>$paste</message>" | |
url="https://thepoint.campfirenow.com/room/$room/speak.xml" | |
ans=`curl -u "$token" -H 'Content-type: application/xml' -d "$msg" $url 2>/dev/null | grep 'starred type'` | |
if [ ${#ans} -eq 0 ]; then | |
echo 'Bad news - sending to campfire failed!' | |
fi | |
echo "${body}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry... there is no need for "ASIC hub"... this is just Bash and
curl
... that's it.