title: Get last line of shell output as a variable
body: <p>I am working on a shell script with exiftool to automatically change some exif tags on pictures contained in a certain folder and I would like to use the output to get a notification on my NAS (a QNAP) when the job is completed.</p>
  
  <p>Everything works already, but - as the notification system truncates the message - I would like to receive just the information I need, i.e. the last line of the shell output, which is for example the following:</p>
  
  <pre><code>Warning: [minor] Entries in IFD0 were out of sequence. Fixed. - 2015-07-12 15.41.06.jpg                                                                             
   4512 files failed condition                                                      
    177 image files updated
  </code></pre>
  
  <p>The problem is that currently I only receive the following notification:</p>
  
  <blockquote>
    <p>Exiftool cronjob completed on Camera: 4512 files failed condition</p>
  </blockquote>
  
  <p>What I would like to get instead is:</p>
  
  <blockquote>
    <p>Exiftool cronjob completed on Camera: 177 image files updated</p>
  </blockquote>
  
  <p>The script is the following:</p>
  
  <pre><code>#!/bin/sh
  # exiftool script for 2002 problem
  dir="/share/Multimedia/Camera"
  cd "$dir"
  FOLDER="$(printf '%s\n' "${PWD##*/}")"
  OUTPUT="$(exiftool -overwrite_original -r '-CreateDate&lt;DateTimeOriginal' -if '$CreateDate eq "2002:12:08 12:00:00"' -if '$DateTimeOriginal ne $CreateDate' *.[Jj][Pp][Gg])"
  /sbin/notice_log_tool -a "Exiftool cronjob completed on ${FOLDER}: ${OUTPUT}" --severity=5
  exit 0
  </code></pre>
  
  <p>To do that I played with the $OUTPUT variable using | tail -1, but probably I make some basic errors and I receive something like:</p>
  
  <blockquote>
    <p>Exiftool cronjob completed on Camera: 4512 files failed condition | tail -1</p>
  </blockquote>
  
  <p>How to do it in the right way? Thanks</p>