简体   繁体   中英

How to convert a directory of XML files in to RRD Files

I need to restore rrd files from my exisiting xml files. So I have used following simple bash script.

#!/bin/bash

for i in /home/dump_xml/*.xml;
do
rrdtool restore $i /home/rrd_new/"${i%.xml}".rrd;
done

I could not execute following script due to this error,

ERROR: Could not create xml reader for: /home/dump_xml/*.xml

But I could restore files one by one. Can someone help me to solve this?

When you use:

for i in /home/dump_xml/*.xml
do
    echo "$i"
done

You will see that $i equals:

  • /home/dump_xml/a.xml
  • /home/dump_xml/b.xml

You see, it contains the path. Therefore your rddtool will try to write the results in /home/dump_xml/home/dump_xml/a.rrd .

You have to do:

#!/bin/bash

for i in xml/*.xml
do
    filename=$(basename "$i")
    rrdtool restore "$i" /home/rrd_new/"${filename%.xml}".rrd;
done

Do not forget to double-quote your variable extensions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM