Difference between revisions of "Bash script running a command"

From thelinuxwiki
Jump to: navigation, search
(Pushed from Themanclub.)

Revision as of 22:25, 25 February 2013


  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