title: How do I stop tail command in script
body: <p>What I want to do - Start capturing the CHANGES to a log file using a custom ssh client code***. After some time (which not a fixed value and is event based), issue a command to stop tailing. This is the command I use to capture the latest changes to a log file - <code>tail -f logfile.txt</code></p>
  
  <p>I want to be able to end it with something like <code>:q</code> which I can issue from a script. I don't want to keyboard commands like <code>ctrl + c</code>.</p>
  
  <p>*** Pseudo code for my custom ssh client code (written in an oop language)</p>
  
  <pre><code>include ssh-api
  ssh = getSSHConnection();
  cmd = 'cd to folder';
  ssh.command(cmd);
  cmd = 'tail -f log.txt';
  ssh.command(cmd);
  wait for special event to occur...
  cmd = 'stop the tail now!'
  out = ssh.command(cmd);
  print "the changes made to log file were\n"  + out;
  </code></pre>
  
  <p>I have no write access to the server where the log file is located.</p>
  
  <p>What I tried - <a href="http://www.linuxquestions.org/questions/red-hat-31/how-to-stop-tail-f-in-scipt-529419/" rel="noreferrer">http://www.linuxquestions.org/questions/red-hat-31/how-to-stop-tail-f-in-scipt-529419/</a></p>
  
  <p>I am not able to understand the solution there (Its in post 2). Can someone please explain the solution or suggest a different way to do this?</p>
  
  <p>Thank you.</p>