Skip to content

Instantly share code, notes, and snippets.

@twentythousandphantoms
Last active December 27, 2022 13:45
Show Gist options
  • Save twentythousandphantoms/b6d493225b44ad4bcfc8b660d4682bd0 to your computer and use it in GitHub Desktop.
Save twentythousandphantoms/b6d493225b44ad4bcfc8b660d4682bd0 to your computer and use it in GitHub Desktop.
A bash script for open files or running tasks monitoring. Can be used with Zabbix
#!/bin/bash
while getopts ":tfp:" optname; do
case "$optname" in
"f")
# Количество открытых файлов
MONITORING_TYPE=0
;;
"t")
# Количество запущенных подзадач
MONITORING_TYPE=1
;;
"p")
# PID-процесса
PID="$OPTARG"
;;
*)
echo "ERROR: Unknown options"
;;
esac
done
case "$MONITORING_TYPE" in
"0")
ls -1 /proc/${PID}/fd | wc -l
;;
"1")
ls -1 /proc/${PID}/task | wc -l
;;
*)
echo "ERROR: Unkown MONITORING_TYPE"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment