【发布时间】:2021-12-21 16:28:57
【问题描述】:
我希望能够在 crontab 中每小时播放一个脚本,同时调用以前在系统启动时定义的环境变量(类似于:export EXTENRALIP=0 在 /etc/profile 等文件中。这个环境变量将是由此脚本修改,该值将在下一次轮换时检索。
我尝试这样做,但导出值不会改变变量
rotation.sh
#!/bin/bash
LOGFILE=/var/log/dns.log
. livebox.sh
. network.sh
. dns.sh
# Grab the var env
IPWAN=$(echo $EXTERNALIP)
# Grab the IPWAN
IP=$(get_livebox_ip)
# Set the var env if changed
if [ "$IPWAN" != "$IP" ]
export EXTERNALIP=$IP
【问题讨论】:
-
/etc/profile在系统启动时不运行。它是在您登录时由您的~/.profile加载的。 -
if [ ... ] export ...语法无效。你错过了then和fi