#!/bin/bash

action=$1

if [ "$action" = "start" ]; then
  nohup sh ./main.sh & echo $! > ./pid &
elif [ "$action" = "stop" ]; then
  kill -9 $(cat ./pid)
fi


#!/bin/bash

action=$1
log=./bat.log

function log {
  echo "$1" > $log
}

if [ "$action" = "start" ]; then
  log "---"
  log "Starting \"Battery alert\""
  sh ./main.sh > $log 2>&1 & echo $! > ./pid &
elif [ "$action" = "stop" ]; then
  log "Stopping \"Battery alert\""
  kill -9 $(cat ./pid)
fi


Replace nohup and log to own log file
Replace nohup and log to own log file