Take Screenshot and Send It to Web Server

A previous post explained how to create a CUPS printer which sends it output as a bitmap images to a web server. This small script gives an example how to post screenshots to the same server backend. The script utilises scrot to take a screenshot and curl to send the image file to the server.

#!/bin/bash

# Takes screenshot (using scrot) and transmit it to server via http (curl)

URL=http://your.server/your/path/index.php

TEMPFILE=`/bin/tempfile --suffix=.jpeg`
echo "Temporary file: ${TEMPFILE}"

/usr/bin/scrot ${TEMPFILE}

/usr/bin/curl -i -F username=${USER} -F page0=@${TEMPFILE} ${URL}
CURL_EXIT=$?

if [ ${CURL_EXIT} -eq 0 ]; then
    zenity --info --text="Kuvan lähetys onnistui"
else
    zenity --error --text="Virhe kuvan lähettämisessä: ${CURL_EXIT}"
fi

rm ${TEMPFILE}

Leave a Reply

Your email address will not be published. Required fields are marked *