script-manager.sh 750 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. echo Running scripts:
  4. ps -eo pid,euser,comm | grep "\.sh$"
  5. echo -e "What you want to do? (example: k [pid], l [script-name]) \\n" \
  6. "k) - kill specific script \\n" \
  7. "K) - killall \\n" \
  8. "l) - list specified \\n" \
  9. "L) - list all \\n"
  10. read -rp "Type here: " choice x
  11. case "$choice" in
  12. k)
  13. echo Killing "$x" ...
  14. kill -9 "$x"
  15. ;;
  16. K) list=$(ps -eo pid,euser,comm | grep "\.sh$" | grep -i "$x" |awk 'NR==1 {print $3}')
  17. echo Killing all "$list" ...
  18. killall -9 "$list"
  19. ;;
  20. l) ps -eo pid,euser,comm | grep "\.sh$" | grep -i "$x"
  21. ;;
  22. L) ps -eo pid,euser,comm | grep "\.sh$"
  23. ;;
  24. *) echo Bad option ;;
  25. esac