Advertisement
Guest User

Untitled

a guest
May 26th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. #!/bin/bash
  2. declare -A array
  3. declare -a arejneki
  4. declare -a arejzimeni
  5. declare -A zakillat
  6. uporabnik=$(whoami)
  7. touch temp.txt
  8. chmod +x temp.txt
  9. touch temp2.txt
  10. chmod +x temp2.txt
  11. while read vrstica < $1
  12. do
  13.  
  14. celota="$vrstica"
  15. kaj="$(cut -d":" -f1 <<< "$celota")"
  16. echo "${array[imeprocesa]}"
  17. if [[ "$kaj" == "run" ]]; then
  18. check="$(cut -d":" -f2 <<< "$celota")"
  19. spanec="$(cut -d":" -f3 <<< "$celota")"
  20. imeprocesa="$(cut -d":" -f4 <<< "$celota")"
  21. kaj="$(cut -d":" -f1 <<< "$celota")"
  22. if [[ $celota = *" "* ]]; then
  23. imeproces2="$(cut -d" " -f1 <<< "$imeprocesa")"
  24. celota2="$imeproces2:$celota"
  25. array[imeprocesa]="$celota2"
  26. else
  27. celota="$imeprocesa:$celota"
  28. array[imeprocesa]="$celota"
  29. fi
  30. zapreverjatime="$(cut -d":" -f1 <<< "${array[imeprocesa]}")"
  31.  
  32.  
  33.  
  34. echo "${array[imeprocesa]}"
  35.  
  36. stevilo=$( pgrep -xfc -g "$$" "$zapreverjatime" )
  37. if ! [ -x "$(command -v ${imeprocesa})" ] || [ "$imeprocesa" == "" ]; then
  38.  
  39. if [ "$imeprocesa" == "" ]; then
  40. ena="./$2"
  41. else
  42. ena="$(cut -d" " -f1 <<< "$imeprocesa")"
  43.  
  44. fi
  45.  
  46.  
  47. echo "Command not runnable: "$ena >&2
  48. else
  49. while true; do
  50. stevilo=$( pgrep -xfc -g "$$" "$zapreverjatime" )
  51.  
  52.  
  53. if [[ $stevilo -lt $check ]]; then
  54. $imeprocesa &
  55.  
  56.  
  57.  
  58. stevilka=$!
  59. zakillat[imeprocesa]+="$stevilka "
  60.  
  61.  
  62.  
  63. echo "$imeprocesa " > temp2.txt
  64. sleep $spanec
  65. echo "${zakillat[imeprocesa]}" > temp.txt
  66. fi
  67.  
  68.  
  69. done &
  70. fi
  71. elif [[ "$kaj" == "exit" ]]; then
  72. kill -- -$$
  73. exit 100;
  74.  
  75. elif [[ "$kaj" == "stop" ]]; then
  76. stevilo="$(cut -d":" -f3 <<< "$celota")"
  77.  
  78. elif [[ "$kaj" == "log" ]]; then
  79. imezapot=""
  80. noustring=""
  81. koncnoime=""
  82. kdajjepraznkdajne=""
  83. while IFS='' read -r line || [[ "$line" ]]; do
  84. imezapot="$( cut -d" " -f1 <<< "$line")"
  85. if [[ $line = *" "* ]]; then
  86. imezapot="$( cut -d" " -f1 <<< "$imezapot")"
  87. kdajjepraznkdajne="$( cut -d" " -f2 <<< "$line")"
  88. else
  89. neki=true
  90. fi
  91.  
  92. done < temp2.txt
  93.  
  94.  
  95.  
  96. echo "$( which "$imezapot" ) $kdajjepraznkdajne"
  97. echo "$( which "$imezapot" ) $kdajjepraznkdajne">>active.log
  98.  
  99.  
  100. while IFS='' read -r line || [[ "$line" ]]; do
  101.  
  102. echo "$line ">>active.log
  103. done < temp.txt
  104.  
  105.  
  106. elif [[ "$kaj" == "log last" ]]; then
  107. imezapot=""
  108. noustring=""
  109. koncnoime=""
  110. kdajjepraznkdajne=""
  111. while IFS='' read -r line || [[ "$line" ]]; do
  112. imezapot="$( cut -d" " -f1 <<< "$line")"
  113. if [[ $line = *" "* ]]; then
  114. imezapot="$( cut -d" " -f1 <<< "$imezapot")"
  115. kdajjepraznkdajne="$( cut -d" " -f2 <<< "$line")"
  116. else
  117. neki=true
  118. fi
  119.  
  120. done < temp2.txt
  121.  
  122.  
  123.  
  124. echo "$( which "$imezapot" ) $kdajjepraznkdajne"
  125. echo "$( which "$imezapot" ) $kdajjepraznkdajne">>active.log
  126.  
  127.  
  128. while IFS='' read -r line || [[ "$line" ]]; do
  129.  
  130. echo "$line ">>active.log
  131. done < temp.txt
  132.  
  133.  
  134. fi
  135.  
  136. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement