sh脚本直接执行返回结果正常,一使用crontab就不正常

38次阅读

共计 882 个字符,预计需要花费 3 分钟才能阅读完成。

内容最后由 skywing 于 2022-12-1 21:44 编辑 #!/usr/bin/env bashget_ip() {        new_ip=`dig domain.com +noall +answer | awk \'{print $5}\’`        old_ip=`iptables -L | grep dpt:443 | grep ACCEPT | awk \'{print $4}\’`}check_ip () {        get_ip        echo "the new ip is $new_ip"        echo "the old ip is $old_ip"        if [[ "${new_ip}" != "${old_ip}" ]]; then        iptables -I INPUT -s $new_ip -p tcp –dport 443 -j ACCEPT        iptables -D INPUT -s $old_ip -p tcp –dport 443 -j ACCEPT        echo "ip changed, update the ip."else        echo "ip not change."        fi}check_ip 复制代码直接执行这个脚本,输出 the new ip is xxxthe old ip is xxxip not change. 复制代码一放到 crontal 里定时执行,输出 the new ip is xxxthe old ip isip changed, update the ip. 复制代码 old_ip 直接返回空值? 这是怎么回事呢?HOH 2022-12-01 21:44 2ipt 在 sbin 里 lifetyper 2022-12-01 21:45 3 楼上应该是正解,这种脚本我都用绝对路径。skywing 2022-12-01 21:54 4HOH 发表于 2022-12-1 21:44ipt 在 sbin 里第一行写成 #/usr/sbin bash 这个脚本就无法通过文件路径直接执行,提示如下错误 -bash: ./ip.sh: /usr/sbin: bad interpreter: Permission denied 必须前面使用 bash 才能正常执行为什么会报这个错误呢?

正文完
 0