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?
Advertisement
Answer
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.