Written by James McDonald

October 21, 2011

They said “James we need someone to check a website and make sure everything is OK over the weekend”. Hmm OK… I’d rather not be tied to a laptop or hang around home so why not send an email with a screenshot to my Android HTC Desire.

Search, search, search:

And then I discovered CutyCapt an app that uses the Webkit QT Rendering Engine to take a screenshot.

I followed the download and install instructions and with Fedora 15 it was easy to compile.

Here is my solution to:

  • Check a website is up firstly. Send error email if it isn’t
  • Take a screen shot in jpeg format
  • Email it to a list of people using mutt connected through a gmail account

CutyCapt running from command line script
Just discovered that this will not work with a cron job. See below for one that does

#!/bin/sh

THIS_DIR=/home/user/get_my_web_site

cd $THIS_DIR || exit

echo removing old jpegs
rm *.jpeg > /dev/null 2>&1

OUTFILE=`date +%Y-%m-%d-%I_%m_%p-my_web_site.jpeg`
MYDATE=`date '+%Y-%m-%d %l:%m %p'`

# here I do a quick check to make sure the site is up using wget
wget --timeout=3 --delete-after --tries=1 http://10.11.12.13  > /dev/null 2>&1

if [ "$?" != "0" ] ; then 

    EMAIL="$MYDATE - ERROR: Cannot access my website!"

    echo "$EMAIL" | mutt -s "$EMAIL" [email protected] -c [email protected] -c [email protected]

else

   EMAIL="$MYDATE My Web Site"

   CutyCapt --max-wait=5000 --url="http://10.11.12.13/cgi-bin/ope/overview.cgi?TIME=0&ZOOM=100&GROUP=1"  --out="$OUTFILE"

   # to get mutt working through your gmail account
   # google "mutt through gmail"
   echo "$EMAIL" | mutt -s "$EMAIL" -a "$OUTFILE"  [email protected] -c [email protected] -c [email protected]
fi


# --min-width=1024 --min-height=768 

CutyCapt running under cron script

To work with Cron you need cutycapt to be run using xvfb-run as below


#!/bin/sh

. /etc/profile

MUTT=/usr/bin/mutt
RM=/bin/rm
DATE=/bin/date
ECHO=/bin/echo
WGET=/usr/bin/wget
CUTYCAPT=/home/user/bin/CutyCapt
XVFBRUN=/usr/bin/xvfb-run


echo removing old jpegs 
# (just make sure there are not other jpegs in the dir you are in!)
$RM *-myWebSite.jpeg > /dev/null 2>&1

# check it's up

OUTFILE=`$DATE +%Y-%m-%d-%I_%M_%p-myWebSite.jpeg`
MYDATE=`$DATE '+%Y-%m-%d %l:%M %p'`


$WGET --timeout=3 --delete-after --tries=1 http://10.11.12.13  > /dev/null 2>&1

if [ "$?" != "0" ] ; then

        EMAIL="$MYDATE - ERROR: Cannot access My Web Site"

        $ECHO "$EMAIL" | $MUTT -s "$EMAIL" [email protected] -c [email protected] -c [email protected]

else

        EMAIL="$MYDATE My Web Site"

$XVFBRUN --server-args="-screen 0, 1024x768x24" $CUTYCAPT --max-wait=5000 --url="http://10.11.12.13/cgi-bin/ope/overview.cgi?TIME=0&ZOOM=100&GROUP=1"  --out="$OUTFILE"

        $ECHO "$EMAIL" | $MUTT -s "$EMAIL" [email protected] -a "$OUTFILE" -c [email protected] -c [email protected]

fi

CutyCapt has got heaps of options:

 -----------------------------------------------------------------------------
 Usage: CutyCapt --url=http://www.example.org/ --out=localfile.png            
 -----------------------------------------------------------------------------
  --help                         Print this help page and exit                
  --url=                    The URL to capture (http:...|file:...|...)   
  --out=                   The target file (.png|pdf|ps|svg|jpeg|...)   
  --out-format=               Like extension in --out, overrides heuristic 
  --min-width=              Minimal width for the image (default: 800)   
  --min-height=             Minimal height for the image (default: 600)  
  --max-wait=                Don't wait more than (default: 90000, inf: 0)
  --delay=                   After successful load, wait (default: 0)     
  --user-style-path=       Location of user style sheet file, if any    
  --user-style-string=      User style rules specified as text           
  --header=:        request header; repeatable; some can't be set
  --method=        Specifies the request method (default: get)  
  --body-string=         Unencoded request body (default: none)       
  --body-base64=         Base64-encoded request body (default: none)  
  --app-name=              appName used in User-Agent; default is none  
  --app-version=        appVers used in User-Agent; default is none  
  --user-agent=          Override the User-Agent header Qt would set  
  --javascript=          JavaScript execution (default: on)           
  --java=                Java execution (default: unknown)            
  --plugins=             Plugin execution (default: unknown)          
  --private-browsing=    Private browsing (default: unknown)          
  --auto-load-images=    Automatic image loading (default: on)        
  --js-can-open-windows= Script can open windows? (default: unknown)  
  --js-can-access-clipboard= Script clipboard privs (default: unknown)
  --print-backgrounds=   Backgrounds in PDF/PS output (default: off)  
  --zoom-factor=          Page zoom factor (default: no zooming)       
  --zoom-text-only=      Whether to zoom only the text (default: off) 
  --http-proxy=             Address for HTTP proxy server (default: none)
 -----------------------------------------------------------------------------
   is svg,ps,pdf,itext,html,rtree,png,jpeg,mng,tiff,gif,bmp,ppm,xbm,xpm    
 -----------------------------------------------------------------------------
 http://cutycapt.sf.net - (c) 2003-2010 Bjoern Hoehrmann - [email protected]

Mutt for GMail Config Example

set from = “[email protected]
set realname = “Mr R J Example”
set imap_user = “[email protected]
set imap_pass = “YOURGMAILPASSWORD”
set folder = “imaps://imap.gmail.com:993”
set spoolfile = “+INBOX”
set postponed =”+[Gmail]/Drafts”
set header_cache =~/.mutt/cache/headers
set message_cachedir =~/.mutt/cache/bodies
set certificate_file =~/.mutt/certificates
set smtp_url = “smtp://[email protected]@smtp.gmail.com:587/”
set smtp_pass = “YOURGMAILPASSWORD”
set move = no
set imap_keepalive = 900
fcc-hook .* ~/.mutt/sent

0 Comments

Submit a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…