title: Running a bash script with an infinite while loop at startup and in the background on a Raspberry Pi
body: <p>I've made a small bash script that I want to run on startup of my Raspberry Pi. I would like this script to run constantly on the machine because I have a mounted USB drive that keeps disconnecting at random times. I use it for media storage and would like to find out at what times it's disconnecting and then remount the drive.</p>
  
  <p>Here is the script</p>
  
  <pre><code>#!/bin/bash
  while : 
  do 
  if mountpoint -q /media/Media
  then
      continue
  else
      echo $(date) &gt;&gt; log.txt
      sudo mount /dev/sda1 /media/Media
  fi
  sleep 1
  done
  </code></pre>
  
  <p>Basically I would like this to run when the Raspberry Pi boots and have it continuously running in the background at all times.</p>
  
  <p>Can anyone give me some help doing this? Thank you.</p>