我的腳本是這樣的,我想爲路徑使用變量以隨時更改它。如何使用$ path和$ storage變量來更改任何內容。其實我從RRD文件獲取數據到XML文件,並希望解析它在python.So,請大家指正如何在linux中爲bash腳本中的文件提供公共路徑
#!/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
路徑=在/ var/lib中/節/的RRD/cluster1中/ ankit21 storage_path = /家庭/ ANKIT/RRD的XML 有一個空間,在這兩個地方後等於 – JSR