gongxiangp2/scripts/check-frp-on-server.sh

118 lines
3.6 KiB
Bash

#!/bin/bash
# Check FRP service status on server
# Check for binary files, systemd services, and process status
echo "========================================"
echo "Check FRP Service Status on Server"
echo "========================================"
echo ""
# 1. Check systemd services
echo "1. Check systemd services..."
echo "----------------------------------------"
if systemctl list-units --type=service | grep -i frp > /dev/null 2>&1; then
echo "[OK] Found FRP systemd services:"
systemctl list-units --type=service | grep -i frp
echo ""
echo "Service status:"
systemctl status frps --no-pager -l 2>/dev/null || echo " frps service not found"
systemctl status frpc --no-pager -l 2>/dev/null || echo " frpc service not found"
else
echo "[WARN] No FRP systemd services found"
fi
echo ""
# 2. Check running processes
echo "2. Check running FRP processes..."
echo "----------------------------------------"
FRP_PROCESSES=$(ps aux | grep -E '[f]rps|[f]rpc' | grep -v grep)
if [ -n "$FRP_PROCESSES" ]; then
echo "[OK] Found FRP processes:"
echo "$FRP_PROCESSES"
echo ""
echo "Process details:"
ps aux | grep -E '[f]rps|[f]rpc' | grep -v grep | while read line; do
PID=$(echo $line | awk '{print $2}')
CMD=$(echo $line | awk '{for(i=11;i<=NF;i++) printf "%s ", $i; print ""}')
echo " PID: $PID"
echo " Command: $CMD"
echo ""
done
else
echo "[WARN] No FRP processes found"
fi
echo ""
# 3. Check binary file locations
echo "3. Check binary file locations..."
echo "----------------------------------------"
BINARIES=$(which frps frpc 2>/dev/null)
if [ -n "$BINARIES" ]; then
echo "[OK] Found FRP binaries in PATH:"
echo "$BINARIES"
else
echo "[WARN] FRP binaries not found in PATH"
fi
echo ""
echo "Searching common locations..."
FOUND_BINARIES=$(find /usr/local/bin /opt /root /home -name '*frp*' -type f -executable 2>/dev/null | head -20)
if [ -n "$FOUND_BINARIES" ]; then
echo "[OK] Found FRP binaries:"
echo "$FOUND_BINARIES"
echo ""
echo "File details:"
echo "$FOUND_BINARIES" | while read binary; do
if [ -f "$binary" ]; then
echo " $binary"
file "$binary" 2>/dev/null
ls -lh "$binary" 2>/dev/null
echo ""
fi
done
else
echo "[WARN] No FRP binaries found in common locations"
fi
echo ""
# 4. Check configuration files
echo "4. Check configuration files..."
echo "----------------------------------------"
CONFIG_FILES=$(find /etc /root /home -name '*frp*.toml' -o -name '*frp*.ini' 2>/dev/null | head -20)
if [ -n "$CONFIG_FILES" ]; then
echo "[OK] Found FRP config files:"
echo "$CONFIG_FILES"
echo ""
echo "Config file details:"
echo "$CONFIG_FILES" | while read config; do
if [ -f "$config" ]; then
echo " $config"
echo " Size: $(ls -lh "$config" | awk '{print $5}')"
echo " First 20 lines:"
head -20 "$config" | sed 's/^/ /'
echo ""
fi
done
else
echo "[WARN] No FRP config files found"
fi
echo ""
# 5. Check network connections
echo "5. Check FRP network connections..."
echo "----------------------------------------"
FRP_CONNECTIONS=$(netstat -tlnp 2>/dev/null | grep -E 'frp|7000|7001' || ss -tlnp 2>/dev/null | grep -E 'frp|7000|7001')
if [ -n "$FRP_CONNECTIONS" ]; then
echo "[OK] Found FRP network connections:"
echo "$FRP_CONNECTIONS"
else
echo "[WARN] No FRP network connections found"
fi
echo ""
echo "========================================"
echo "Check completed!"
echo "========================================"