Skip to content

Instantly share code, notes, and snippets.

@cronnelly
Created October 25, 2012 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cronnelly/3952563 to your computer and use it in GitHub Desktop.
Save cronnelly/3952563 to your computer and use it in GitHub Desktop.
Serve X display snapshot over HTTP
#!/bin/bash
# Call from inet with this config:
# www stream tcp nowait node /usr/local/bin/screen_serve.sh
export XAUTHORITY=/home/node/.Xauthority
export DISPLAY=:0
filename="/tmp/screen-"$(uuidgen)".jpg"
for i in `seq 100`; do
read header
[ "$header" == $'\r' ] && break;
done
echo "HTTP/1.1 200 OK"
echo "Content-Type: image/jpeg"
/usr/bin/gm import -window root -quality 10 "$filename"
echo "Content-Length: "$(stat -c%s "$filename")
echo
cat "$filename"
echo
rm "$filename"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment