Bash script running a command

From thelinuxwiki
Revision as of 22:25, 25 February 2013 by Nighthawk (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


  1. !/bin/bash
      1. 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