Bash script running a command

From thelinuxwiki
Jump to: navigation, search


#!/bin/bash
### Run command for given number of seconds then kill it
read -p "How long should I run for? ==> " count_secs
if [ $count_secs -gt 0 ]
then
  ###
  ### number of seconds greater than zero
  ###
  /my/command &
  ###
  ### assume that the PID of the command is $$
  ###
  my_PID=$$
  sleep $count_secs
  kill -15 $my_PID
fi