Bash script running a command

From thelinuxwiki
Revision as of 01:29, 20 July 2013 by Nighthawk (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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