Difference between revisions of "Bash script running a command"

From thelinuxwiki
Jump to: navigation, search
(Pushed from Themanclub.)
 
 
Line 1: Line 1:
  
  
#!/bin/bash
+
#!/bin/bash
 +
### Run command for given number of seconds then kill it
  
###
+
read -p "How long should I run for? ==> " count_secs
### 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
if [ $count_secs -gt 0 ]
+
then
+
 
   ###
 
   ###
 
   ### number of seconds greater than zero
 
   ### number of seconds greater than zero
Line 23: Line 20:
 
   sleep $count_secs
 
   sleep $count_secs
 
   kill -15 $my_PID
 
   kill -15 $my_PID
fi
+
fi
  
 
[[category:bash]]
 
[[category:bash]]

Latest revision as of 01:29, 20 July 2013


#!/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