|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 虾仁 于 2014-12-22 20:42 编辑
eth0 = commands.getoutput("ifconfig eth0|awk -F'[ ]+|[:]' 'NR==2{print $4}'")
for (k,v) in hosts.items():
if hosts[k] == eth0:
hname = k
# print hname #(会打印出来很多主机名)
print hname #会打印出一个。
dis = {'InstanceId': oid,'Name': hname}
以上代码如果直接使用python xxx.py 是可用得到正确的结果的,但是把它加入到crontab中
*/5 * * * * /usr/bin/python /home/ecr/xxx.py
结果会得到:
Traceback (most recent call last):
File "/home/ecr/xxx.py", line 98, in <module>
print hname
NameError: name 'hname' is not defined
请教这个是什么原因,如何解决喔??
原因是:
eth0 = commands.getoutput("/sbin/ifconfig eth0|awk -F'[ ]+|[:]' 'NR==2{print $4}'")
python 调用shell命令时候需要写全路径名称
|
|