【问题标题】:Linux Bash Script use return of functionLinux Bash 脚本使用函数返回
【发布时间】:2013-07-24 19:35:04
【问题描述】:

我的脚本有问题。

我编写了一个脚本“getip.sh”,每小时都会调用一次。该脚本获取当前本地IP并调用wget来传输这个IP地址像这样

http://example.com/index.php?localip=192.168.0.1

如果我使用 ./getip.sh 手动调用脚本,一切正常。 如果通过 crontab 调用此脚本:

* * * * * cd /home/pi && ./getip.sh >> /home/pi/myLog

网络服务器只接收以下内容 http://example.com/index.php?localip=

有人知道这个问题吗?

#!/bin/bash

html="http://example.com/index.php?localip=";
netip=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;
netcomp=$html$netip;
wget -O /dev/null -q $netcomp
echo $netcomp

【问题讨论】:

    标签: linux shell crontab


    【解决方案1】:

    cron 的路径不包括 /sbin。使用完整路径调用 ifconfig:

    netip=`/sbin/ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;
    

    【讨论】:

      【解决方案2】:

      你有这样的测试吗:

          * * * * * /home/pi/getip.sh >> /home/pi/myLog
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-20
        • 2011-07-29
        • 1970-01-01
        • 1970-01-01
        • 2018-07-02
        • 2020-09-24
        • 2016-09-23
        相关资源
        最近更新 更多