Bds-Maneger-CLI-Debian/bin/bds-status

23 lines
861 B
Bash

#!/bin/bash
pid=$(ps -fu $USER|grep -v 'grep'|grep "bedrock_server"|awk '{print $2}' | head -1)
if [ -z $pid ]; then
echo "ERROR: Process ID not specified."
exit 13
fi
kill -0 $pid > /dev/null 2>&1
pid_exist=$?
if [ $pid_exist == 0 ]; then
latestscpu=$(top -b -n 1 -p $pid | grep -w -E "^ *$pid" | awk '{print $9}' | sed "s|$pid||g" | sed 's|root||g' | sed 's|bedrock_server||g' | tr 'n' , | sed s/,$// | awk '{print substr($0, 1, 6)}'|sed 's| ||g'| sed -E 's|,[0-9],||g'| sed -E 's|,[0-9]||g')
ME="$(ps -o rss= $pid | awk '{printf "%.0f\n", $1 / 1024}')"
ME2="$(ps -o vsz= $pid | awk '{printf "%.0f\n", $1 / 1024}')"
while true
do
case $1 in
CPU|cpu) echo "$latestscpu";;
MEM|mem) echo "$ME";;
MEMV|memv) echo "$ME2";;
ALL|all) echo "Utilizações: CPU $latestscpu )-( Memoria $ME MB )-( Memoria Virtual $ME2 MB";;
esac
done
fi