python - 如何在 linux 中的 bash 脚本中为文件提供公共(public)路径

标签 python linux bash

我的脚本是这样的,我想使用变量作为路径以便随时更改它。我如何使用 $path 和 $storage 变量来更改它。实际上我正在将数据从 rrd 文件获取到 xml 文件并想在python中解析它。所以,请纠正我

#!/bin/bash

echo "hello ak"
path= /var/lib/ganglia/rrds/cluster1/ankit21
storage_path= /home/ankit/rrd-xml

rrdtool xport -s -25m DEF:xx=$path/bytes_in.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/bytes_in.xml
rrdtool xport -s -25m DEF:xx=$path/bytes_out.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/bytes_out.xml
rrdtool xport -s -25m DEF:xx=$path/cpu_aidle.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/cpu_aidle.xml
rrdtool xport -s -25m DEF:xx=$path/cpu_idle.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/cpu_idle.xml
rrdtool xport -s -25m DEF:xx=$path/cpu_num.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/cpu_num.xml
rrdtool xport -s -25m DEF:xx=$path/cpu_system.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/cpu_system.xml
rrdtool xport -s -25m DEF:xx=$path/cpu_user.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/cpu_user.xml
rrdtool xport -s -25m DEF:xx=$path/cpu_wio.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/cpu_wio.xml
rrdtool xport -s -25m DEF:xx=$path/disk_free.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/disk_free.xml
rrdtool xport -s -25m DEF:xx=$path/disk_total.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/disk_total.xml
rrdtool xport -s -25m DEF:xx=$path/load_fifteen.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/load_fifteen.xml
rrdtool xport -s -25m DEF:xx=$path/load_one.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/load_one.xml
rrdtool xport -s -25m DEF:xx=$path/mem_buffers.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/mem_buffers.xml
rrdtool xport -s -25m DEF:xx=$path/mem_cached.rrd:sum:AVERAGE XPORT:xx:    >$storage_path/mem_cached.xml
rrdtool xport -s -25m DEF:xx=$path/mem_free.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/mem_free.xml
rrdtool xport -s -25m DEF:xx=$path/mem_shared.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/mem_shared.xml
rrdtool xport -s -25m DEF:xx=$path/mem_total.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/mem_total.xml
rrdtool xport -s -25m DEF:xx=$path/pkts_in.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/pkts_in.xml
rrdtool xport -s -25m DEF:xx=$path/pkts_out.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/pkts_out.xml
rrdtool xport -s -25m DEF:xx=$path/proc_run.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/proc_run.xml
rrdtool xport -s -25m DEF:xx=$path/proc_total.rrd:sum:AVERAGE XPORT:xx:    >$storage_path/proc_total.xml
rrdtool xport -s -25m DEF:xx=$path/swap_free.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/swap_free.xml
rrdtool xport -s -25m DEF:xx=$path/swap_total.rrd:sum:AVERAGE XPORT:xx:    > $storage_path/swap_total.xml

python $storage_path/zget.py


And the errors are ...
 hello ak
./zscript.sh: line 4: /var/lib/ganglia/rrds/cluster1/ankit21: Is a directory
./zscript.sh: line 5: /home/ankit/rrd-xml: Is a directory
ERROR: opening '/bytes_in.rrd': No such file or directory
ERROR: opening '/bytes_out.rrd': No such file or directory
ERROR: opening '/cpu_aidle.rrd': No such file or directory
ERROR: opening '/cpu_idle.rrd': No such file or directory
ERROR: opening '/cpu_num.rrd': No such file or directory
ERROR: opening '/cpu_system.rrd': No such file or directory
ERROR: opening '/cpu_user.rrd': No such file or directory
ERROR: opening '/cpu_wio.rrd': No such file or directory
ERROR: opening '/disk_free.rrd': No such file or directory
ERROR: opening '/disk_total.rrd': No such file or directory
ERROR: opening '/load_fifteen.rrd': No such file or directory
ERROR: opening '/load_one.rrd': No such file or directory
ERROR: opening '/mem_buffers.rrd': No such file or directory
ERROR: opening '/mem_cached.rrd': No such file or directory
ERROR: opening '/mem_free.rrd': No such file or directory
ERROR: opening '/mem_shared.rrd': No such file or directory
ERROR: opening '/mem_total.rrd': No such file or directory
ERROR: opening '/pkts_in.rrd': No such file or directory
ERROR: opening '/pkts_out.rrd': No such file or directory
ERROR: opening '/proc_run.rrd': No such file or directory
ERROR: opening '/proc_total.rrd': No such file or directory
ERROR: opening '/swap_free.rrd': No such file or directory
ERROR: opening '/swap_total.rrd': No such file or directory
python: can't open file '/zget.py': [Errno 2] No such file or directory

最佳答案

看来错误在行中

path= /var/lib/ganglia/rrds/cluster1/ankit21

我认为问题是空间......

另外,尝试用引号引起来。

路径="/tmp/测试"

This做一些有趣的阅读。

关于python - 如何在 linux 中的 bash 脚本中为文件提供公共(public)路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34229200/

相关文章:

linux - 注释掉Printf导致段错误

Bash:在管道中间设置一个shell变量

php - 从 php 执行 bash 脚本并即时输出回网页

python - opencv inRange像素位置

python - 在 Pandas 数据帧上并行操作时速度慢

php - 如何同时运行多个 Laravel 命令?

linux - 如何阻止 linux 程序被打印筛选?

python - 更优雅的方式来做到这一点?

python - 在 iPython 中使用 style.format 打印 pandas df

node.js - Mac OS X Mavericks 更新后,使用 npm 进行全局安装不起作用