#!/bin/bash
#Using a file to control the operation of a bash script
#Handy in situations where you are looking for a log file or another process or job to create/update or delete a file
#Also can be used for lock files, core dumps, etc...
control_file="/tmp/control"
control_value="start"
if [ -e $control_file ] ; then
    echo "Terminating due to the presence of the control file $control_file"
    echo "No actions were perfomred"
    exit
fi

echo "I will continue to run until I detect the control file $control_file"
echo "You can stop this script by creating the control file e.g."
echo "# touch $control_file"
until [ -e $control_file  ]
    do
    echo "Performing some arbitrary action....." && sleep 1
    done
echo Program $0 has finished.