SHARE
TWEET

Untitled

a guest May 19th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #/bin/bash
  2. p=-10
  3. s=2
  4. n=3
  5. t=300
  6. potprocesa="$1"
  7. potprocesa=$(echo "$potprocesa" | cut -d" " -f1)
  8. echo "$potprocesa"
  9. if [ -z "$potprocesa" ]
  10. then
  11.     potprocesa="$1"
  12. fi
  13. if [ "$#" -eq 2 ]
  14. then
  15.     conffile="$2"
  16. fi
  17. if [[ ! -z "$conffile" ]]
  18. then
  19.     if [ -f "$conffile" ]
  20.     then
  21.         while IFS= read -r vrstica
  22.         do
  23.             IFS=':' read -ra polje <<< "$vrstica"
  24.             [[ "${polje[0]}" = "p" ]] && p="${polje[1]}"
  25.             [[ "${polje[0]}" = "s" ]] && s="${polje[1]}"
  26.             [[ "${polje[0]}" = "n" ]] && n="${polje[1]}"
  27.             [[ "${polje[0]}" = "t" ]] && t="${polje[1]}"
  28.             [[ "${polje[0]}" = "log" ]] && log="${polje[1]}"
  29.         done < "$conffile"
  30.     fi
  31. fi
  32. procesia=$(ps -eo pid,ni,cmd)
  33. IFS=$'\n' read -rd '' -a procesib <<<"$procesia"
  34. procesib=("${procesib[@]:1}")
  35. unset 'procesib[${#procesib[@]}-1]'
  36. re='^[+-]?[0-9]+$'
  37. instances=0
  38. for proces in "${procesib[@]}"
  39. do
  40.     processplit=($proces)
  41.     if [[ "${processplit[1]}" =~ $re ]]
  42.     then
  43.         a="${processplit[1]}"
  44.         a=$((a + s))
  45.     fi
  46.     if [[ "${processplit[2]}" ==  "$potprocesa" ]]
  47.     then
  48.         renice -n "$p" "${processplit[0]}"
  49.         instances=$((instances + 1))
  50.     else
  51.         renice -n "$a" "${processplit[0]}"
  52.     fi
  53. done
  54. timer=$(awk -v t=$t 'BEGIN { print t / 1000 }')
  55. while [[ "$instances" -lt "$n" ]]
  56. do
  57.     sleep "$timer"
  58.     instances=$((instances + 1))
  59.     eval "$1" &
  60. done
  61.  
  62. echo "Na tem mestu, $(date +"%-d. %-m.") je Zajec Veliki pomagal procesu $potprocesa."
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top