【发布时间】:2016-08-01 11:36:44
【问题描述】:
我有简单的 bash 脚本,该脚本在终端上工作手册,但在 cron 之后给出了一个空变量。
#!/bin/bash
gwip=`/usr/bin/nmcli dev list iface eth0 | grep IP4-SETTINGS.GATEWAY: | awk '{ print $2}'`
printf '%s\n' "$(date) =- $gwip -= " >> /var/log/looog.log
运行:/bin/bash /test.bash
在文件 /var/log/looog.log 中输出:
1 monday 2016 14:17:36 +0300 =- 23.18.117.254 -=
当我运行 cron 时,变量为空。
*/1 * * * * root /bin/bash /test.bash
在文件 /var/log/looog.log 中输出:
1 monday 2016 14:19:13 +0300 =- -=
为什么变量 $gwip 是空的?如何解决?
【问题讨论】: