title: Linux bash script with stop/start option
body: <p>I developed a script that find the number of running thread by given PID (as argument). we can run it once and everything work perfect.
  but, for our need i must make it to run with start and stop option.
  means, until i'm not make it stop the script week logging the thread number.
  i tried to do so in my code below but seems no luck</p>
  
  <pre><code>PID=$1
  Command=$2
  scriptPID=`echo $$`
  #going to check if arguments were supplied if not using the defaults. if only one argument supplied then aborting.
  if [[ $PID -eq 0 ]]
          then
                   echo -e "\n[ERROR]: No PID was provided. please provide PID as argument.\n"
                   exit 1
  fi
  initCommand(){
         #local Command="$2";
         case $Command in
                start)
                       start "true"
                       ;;
                stop)
                       stop -f "true"
                                          ;;
         esac
  }
  start(){
  #going redirect stout &amp; stderr to log file
  echo "starting"
  echo "script PID $scriptPID"
  exec 1&gt;&gt;pidThreadNumber.log 2&gt;&amp;1
  while (true); do
  runningThreads=`ps huH p $PID | wc -l`
  date;
  echo "-------------------------------"
  echo -e "Number of running threads: "$runningThreads"\n\n" 
  sleep 2
  done
  }
  stop()
  {
  kill -9 $scriptPID
  }
  initCommand $Command
  </code></pre>
  
  <p>Thank you all for the help</p>