/[cricket]/rrdedit
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /rrdedit

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Wed Nov 19 18:20:22 2003 UTC (20 years, 4 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
interactivly edit rrd files. Just add one or more files as arguement
to this command, and it will bring up first file in your $EDITOR (or vi).
Edit file, and save it. It will then make a diff and try to apply diff to
all other files. If sucessfull, it will perform same operation on real files
(leaving originals with extension .bak)

1 #!/bin/sh
2
3 # small interactive script which enables you to edit one rrd file in our
4 # favourite EDITOR (vi, right?) and then apply that changes (using diff
5 # and patch) to multiple files
6 #
7 # Dobrica Pavlinusic <dpavlin@rot13.org> 2003-11-19
8
9 if [ -z "$1" ] ; then
10 echo "Usage: $0 [rrd file] ..."
11 exit 1
12 fi
13
14 if [ ! -z "$EDITOR" ] ; then
15 editor=$EDITOR
16 else
17 editor=vi
18 fi
19
20 b=`basename $0`
21
22 xmlfile=/tmp/$b.xml
23 rrddiff=/tmp/$b.diff
24 rrdtmp=/tmp/$b-tmp.rrd
25
26 rrdtool dump $1 > $xmlfile
27 cp -p $xmlfile /tmp/$1
28
29 $editor /tmp/$1
30
31 diff -uw $xmlfile /tmp/$1 > $rrddiff
32
33 echo "diff between original file and edited one:"
34 cat $rrddiff
35
36 faildiff=""
37 failrrd=""
38 echo "trying to apply to all sources"
39 for rrdfile in $@ ; do
40 echo " $rrdfile"
41 rrdtool dump $rrdfile > $xmlfile
42 patch -s -p0 $xmlfile $rrddiff || faildiff="$faildiff $rrdfile"
43 err=`rrdtool restore $xmlfile $rrdtmp 2>&1`
44 rm -f $rrdtmp
45 if [ ! -z "$err" ] ; then
46 failrrd="$failrrd $rrdfile"
47 fi
48 done
49
50 if [ ! -z "$faildiff" ] ; then
51 echo "can't apply diff on files:$faildiff, aborting!"
52 exit 1
53 fi
54
55 if [ ! -z "$failrrd" ] ; then
56 echo "can't restore xml to rrd for files:$failrrd [$err], aborting!"
57 exit 1
58 fi
59
60 echo "all files can be converted, doing it for real..."
61
62 for rrdfile in $@ ; do
63 echo " $rrdfile"
64 rrdtool dump $rrdfile > $xmlfile
65 patch -s -p0 $xmlfile $rrddiff && \
66 mv $rrdfile ${rrdfile}.bak && \
67 rrdtool restore $xmlfile $rrdfile
68 done

  ViewVC Help
Powered by ViewVC 1.1.26