Imported Upstream version 2.4.4p3
[debian/amanda] / amplot / amplot.sh.in
1 #!/bin/sh
2 # Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 # Copyright (c) 1992-1998 University of Maryland at College Park
4 # All Rights Reserved.
5 #
6 # Permission to use, copy, modify, distribute, and sell this software and its
7 # documentation for any purpose is hereby granted without fee, provided that
8 # the above copyright notice appear in all copies and that both that
9 # copyright notice and this permission notice appear in supporting
10 # documentation, and that the name of U.M. not be used in advertising or
11 # publicity pertaining to distribution of the software without specific,
12 # written prior permission.  U.M. makes no representations about the
13 # suitability of this software for any purpose.  It is provided "as is"
14 # without express or implied warranty.
15 #
16 # U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #
23 # Author: Olafur Gudumundsson, (ogud@tis.com)  Trusted Information Systems
24 # Formerly at:            Systems Design and Analysis Group
25 #                         Computer Science Department
26 #                         University of Maryland at College Park
27 #
28 #       Amplot: a program to generate postscript plots of each nights amanda 
29 #       performance 
30
31 #       Author: Olafur Gudmundsson (ogud@tis.com) 
32 #       Creation Date: April 1992 
33 #       Last modified: April 1995 
34 #       Input: list of amdumps 
35 #       Output: Plot of amdump files as either gnuplots on the screen or
36 #               Postscript files 
37 #
38
39 prefix=@prefix@
40 exec_prefix=@exec_prefix@
41 sbindir=@sbindir@
42 libexecdir=@libexecdir@
43  
44 confdir=@CONFIG_DIR@
45  
46 PATH=$sbindir:$libexecdir:/usr/bin:/bin:/usr/sbin:/sbin:/usr/ucb:$PATH
47 export PATH
48
49 AWK=@AWK@
50 AVARFLAG=@AWK_VAR_ASSIGNMENT_OPT@
51 GNUPLOT=@GNUPLOT@
52 COMPRESS=@AMPLOT_COMPRESS@
53
54 if [ $# -eq 0 ] ; then
55         echo "Usage: $0 [-c] [-e] [-g] [-l] [-p] [-t hours] <amdump_files.[gz,z,Z]>"
56         echo "amplot generates plot for screen with fixed dimensions"
57         echo "  -c      Compress the input amdump files after plotting"
58         echo "  -e      Extends x (time) axes if needed"
59         echo "  -g      Run gnuplot directly no postscript file generated DEFAULT"
60         echo "  -l      Landscape mode suitable for printing"
61         echo "  -p      Postscript output (color)"
62         echo "  -b      The postscipt will be b/w"
63         echo "  -t T    Set the right edge of the plot to be T hours"
64         exit 1 
65 fi
66
67 tmp_files="bandw_free disk_alloc dump_idle finished run_queue tape_* title" 
68
69 my_plot=$libexecdir/amplot.g
70 paper=0 
71 gnuplot=1
72 cmpres=0
73 para=""
74 maxtime=4
75 bw=0
76
77 # setting up the parameters to pass to [gn]awk 
78 while :; do 
79    case "$1" in
80    -c)  cmpres=1; shift;;
81    -e)  para=$para"$AVARFLAG extend=1 "; shift;;
82    -g)  gnuplot=1; shift;;
83    -l)  paper=1; para=$para"$AVARFLAG paper=1 "; shift;;
84    -p)  gnuplot=0; shift;;
85    -b)  bw=1; shift;;
86    -t)  shift
87         if test "$#" -eq 0; then
88             echo "amplot: no argument for -t option" 1>&2
89             exit 5
90         fi
91         maxtime="$1"; shift;;
92    *) break;;
93    esac
94 done
95 if [ $# -eq 0 ] ; then 
96         echo "amplot: no input files" 1>&2
97         exit 5
98 fi
99 para=$para"$AVARFLAG maxtime=$maxtime"
100
101 if [ $gnuplot  -eq 1 ] ; then
102         my_plot=$my_plot"p"             # use the plot prog that pauses
103         plot=" -geometry 800x700+40+0" 
104         para=$para"$AVARFLAG gnuplot=1 "
105         echo "Displaying graph on the screen, <CR> for next graph"
106
107         if [ "$paper" -eq 1 ] ; then
108                 echo "amplot: -l requires -p flag at the same time" 1>&2
109                 exit 6 
110         fi
111         if [ "$bw" -eq 1 ] ; then
112                 echo "amplot: -b requires -p flag at the same time" 1>&2
113                 exit 6 
114         fi
115 fi
116
117 if [ $bw -eq 1 ]; then
118         para=$para" bw=1"
119 fi
120
121 list="";                # files to compress at the end
122
123 for i in ${1+"$@"}              # for all the input files
124 do
125         f="$i";
126         if [ ! -f "$f" ] ; then 
127                 f=`ls "$i" "$i".*[zZ] 2>/dev/null`
128         fi
129         if [ -f "$f" ] ; then           # found file 
130                 disp=`$AWK -f $libexecdir/amcat.awk $AVARFLAG f="$f"`
131                 if [ -z "$disp" ] ; then 
132                         echo "Do not know how to [gz|z]cat this file"
133                 else
134                         /bin/rm -f $tmp_files 
135                         $disp "$f" | $AWK -f $libexecdir/amplot.awk $para
136                         $GNUPLOT $plot $my_plot
137                         if [ $disp = "cat" -a  $cmpres -eq 1 ] ; then
138                                 list=$list" "$f
139                         fi
140                 fi
141         else                            # check if file has been compressed
142                 echo "No such file $i or $i.*[zZ]"
143         fi
144 done
145
146 /bin/rm -f $tmp_files 
147
148 if [ "$list" != "" ] ; then             # now compress the files we worked on
149 # comment out next line if you do not want compression at the end
150         echo "Compressing $list"
151         $COMPRESS $list
152 fi
153 exit 0