status.sh 515 B

1234567891011121314151617181920
  1. #!/usr/bin/env bash
  2. set -e
  3. app_name="CloudflareServer"
  4. pid=$(ps -auxw | grep ${app_name} | grep -vE "grep|-Xmx700m" | awk '{print $2}')
  5. if [[ $pid == "" ]]; then
  6. echo "${app_name} 未在运行"
  7. else
  8. running_time=$(ps -o etime= -p "$pid")
  9. ports=$(netstat -tnlp | grep ${app_name:0:10} | head -n +1 | awk '{print $4}')
  10. echo "${app_name}当前PID: $pid"
  11. echo "当前运行时间: $running_time" | tr -s " "
  12. echo "当前运行端口:"
  13. for i in "$ports"; do
  14. echo "$i"
  15. done
  16. fi