hervasiop12345

encolapro

Aug 16th, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.86 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. #Author:jMa
  4. #
  5. #Description: Ejecuta los procesos pasados como parĂ¡metro en segundo plano y espera a que termine uno
  6. #para ejecutar otro.
  7. #
  8. #Sintax: ./encolapro -t tiempo [proceso1] ...[procesoN]
  9. #        ./encolapro [proceso1] ...[procesoN] (En este caso se toman 60 segundos de tiempo)
  10. #
  11.  
  12. echo $2 | grep -x -q "[0-9]\+"
  13. num=$?    
  14.  
  15. function process {
  16.     $1 2> /dev/null &
  17.     pid=$!
  18.     while [ `ps aux | tr -s " " | cut -d " " -f 2| grep $pid | wc -l` -gt 0 ]
  19.     do
  20.       sleep $tiempo
  21.     done    
  22. }
  23.  
  24. if [ \( "$1" == "-t" \) ] && [ \( "$num" == 0 \) ]
  25. then
  26.   tiempo=$2
  27.   shift
  28.   shift
  29.   while true
  30.   do
  31.     if [ "$1" = "" ]
  32.     then
  33.       break
  34.     fi  
  35.     process $1
  36.     shift
  37.   done
  38. else
  39.   tiempo=60
  40.   while true
  41.   do
  42.     if [ "$1" = "" ]
  43.     then
  44.       break
  45.     fi
  46.     process $1
  47.     shift
  48.   done  
  49. fi
Advertisement
Add Comment
Please, Sign In to add comment