Some checks failed
Weekly Translation Workflow / translate (push) Has been cancelled
- Replace 'docker run -p 80:80' with '--network host' for certbot standalone HTTP-01 to avoid timeout in environments where Docker NAT port-publish breaks LE inbound traffic but host port 80 is reachable. - Applies to kejilion.sh (all locale variants) and auto_cert_renewal.sh. - README install command points to this Gitea mirror.
34 lines
909 B
Bash
34 lines
909 B
Bash
#!/bin/bash
|
|
|
|
# 获取总的接收和发送流量
|
|
output=$(awk 'BEGIN { rx_total = 0; tx_total = 0 }
|
|
$1 ~ /^(eth|ens|enp|eno)[0-9]+/ { rx_total += $2; tx_total += $10 }
|
|
END {
|
|
printf("%.0f Bytes %.0f Bytes", rx_total, tx_total);
|
|
}' /proc/net/dev)
|
|
|
|
|
|
# 获取接收和发送的流量数据
|
|
rx=$(echo "$output" | awk '{print $1}')
|
|
tx=$(echo "$output" | awk '{print $3}')
|
|
|
|
# 显示当前流量使用情况
|
|
echo "当前接收流量: $rx"
|
|
echo "当前发送流量: $tx"
|
|
|
|
threshold_gb=110
|
|
|
|
# 将GB转换为字节
|
|
threshold=$((threshold_gb * 1024 * 1024 * 1024))
|
|
|
|
# 检查是否达到流量阈值
|
|
if (( $rx > $threshold || $tx > $threshold )); then
|
|
echo "流量达到${threshold},正在关闭服务器..."
|
|
# 在此处执行关闭服务器的命令,例如:
|
|
shutdown -h now
|
|
# 或者
|
|
# systemctl poweroff
|
|
else
|
|
echo "当前流量未达到${threshold},继续监视..."
|
|
fi
|