title: grab last n lines from console output
body: <p>I want to make a shell script that will effectively grab the last n lines from sterr and stin that were outputted to the console. I have a screen session running a process that will restart it if it crashes via a hacky infinite loop:</p>
  
  <pre><code>#!/bin/bash
  #This script will be started in a screen session
  counter=0
  while [ $counter -lt 10 ]; do
      ./run_some_process;
       last_output=#GRAB PREVIOUS OUTPUT FROM CONSOLE HERE AND LOG TO FILE
       echo -e "$last_output" &gt;&gt; mylog.txt;
      sleep 5; #sleep for a few seconds before restarting
  done
  </code></pre>
  
  <p>What I need is for the 7th line of code to grab the last 10 or so lines from stderr and stdin and append them to a log file</p>