本帖最后由 sanmoking 于 2024-12-24 01:48 编辑
我用的ddnsgo解析ipv6,但是一旦遇到光猫重启或者路由器重启,ha就会获取多个ipv6的地址,然后域名解析就容易出错,我把群会上用的sh脚本拿来改了改,根据ip的有效期来删除旧的ipv6:
#!/bin/bash
echo "检查网口enp0s3"
lan1_ipv6_addr_count=`ip -6 a s enp0s3 | grep -E -c "2408|2409|240a|240e"`
if [[ $lan1_ipv6_addr_count = 1 || $lan1_ipv6_addr_count = 0 ]]; then
echo "IPV6地址数量为" $lan1_ipv6_addr_count ",不进行操作"
else
echo "IPV6地址数量为" $lan1_ipv6_addr_count ", 开始查找"
for i in {2..$lan1_ipv6_addr_count..1}
do
lan1_ipv6_addr_lastip=`ip -6 a s enp0s3 | grep -A1 'inet6 [^f:]'|grep -v ^--|sed -nr ':a;N;s#^ +inet6 ([a-f0-9:]+/.+?) scope global .*? valid_lft ([0-9]+sec) .*#\2 \1#p;Ta'|sort -n|head -n1|cut -d' ' -f2`
echo "最老的IPV6地址为" $lan1_ipv6_addr_lastip ", 开始删除"
ip -6 addr del $lan1_ipv6_addr_lastip dev enp0s3
done
fi
我给它放到这里【/mnt/data/supervisor/homeassistant/1234/del_old_ipv6.sh】,也就是File editor打开就看到的位置,方便用:
然后在/homeassistant/configuration.yaml配置文件里面加了这个:
shell_command:
del_old_ipv6: sh /mnt/data/supervisor/homeassistant/1234/del_old_ipv6.sh
我在ssh里面运行是正常的:
然后做了个自动化:
alias: del old ipv6
description: ""
triggers:
- trigger: state
entity_id:
- sensor.system_monitor_ipv6_address_enp0s3
from: null
to: null
conditions: []
actions:
- action: shell_command.del_old_ipv6
data: {}
mode: single
但是运行之后,日志报错,各位大佬帮忙看看是咋回事
2024-12-24 00:03:34.867 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `sh /mnt/data/supervisor/homeassistant/1234/del_old_ipv6.sh`, return code: 2
NoneType: None
|