2 # Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 # Copyright (c) 1992-1998 University of Maryland at College Park
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.
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.
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
28 # Amplot: a program to generate postscript plots of each nights amanda
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
40 exec_prefix="@exec_prefix@"
42 amlibexecdir="@amlibexecdir@"
43 . "${amlibexecdir}/amanda-sh-lib.sh"
47 # add sbin and ucb dirs
48 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
51 # we use a different version of the compression variable than amanda itself.
52 COMPRESS=@AMPLOT_COMPRESS@
54 # Function to check that awk can do command-line variable
55 # substitution. If no, then exit; if yes, set $AVARFLAG
56 # to the commandline switch used to introduce a variable. This
57 # check used to be performed at build time in configure; it's
58 # now performed at runtime.
61 tmpfile=`mktemp /tmp/amplot.XXXXXX`
62 echo 'BEGIN{print i; exit}' > ${tmpfile}
63 result=`$AWK -f ${tmpfile} i=xx | wc -c`
64 if test "$result" -le 1; then
65 result=`$AWK -f ${tmpfile} -v i=xx | wc -c`
66 if test "$result" -le 1; then
67 echo "$AWK does not support command-line variable assignment; amplot cannot run" >&2
80 # Function to search for gnuplot and ensure it's working. This
81 # first tries the location detected/configured when amanda was built,
82 # then tries 'gnuplot', assuming it's in the user's path. If no
83 # working gnuplot executable is found, it exits with an error. The
84 # variable $GNUPLOT is set to the resulting executable.
86 if test "x$GNUPLOT" = "x"; then
87 # look for it in the user's PATH
91 if ${GNUPLOT} --version 2>/dev/null | grep '^gnuplot' >/dev/null; then
94 echo "${GNUPLOT} was not found; amplot cannot run"
99 # check our environment, using functions from above
103 if [ $# -eq 0 ] ; then
104 _ 'Usage: %s [-c] [-e] [-g] [-l] [-p] [-t hours] <amdump_files.[gz,z,Z]>\n' $0
105 _ '%s generates plot for screen with fixed dimensions\n' $0
106 _ ' -c Compress the input amdump files after plotting\n'
107 _ ' -e Extends x (time) axes if needed\n'
108 _ ' -g Run gnuplot directly no postscript file generated DEFAULT\n'
109 _ ' -l Landscape mode suitable for printing\n'
110 _ ' -p Postscript output (color)\n'
111 _ ' -b The postscipt will be b/w\n'
112 _ ' -t T Set the right edge of the plot to be T hours\n'
116 tmp_files="bandw_free disk_alloc dump_idle finished run_queue tape_* title"
118 my_plot=$amlibexecdir/amplot.g
126 # setting up the parameters to pass to [gn]awk
129 -c) cmpres=1; shift;;
130 -e) para=$para"$AVARFLAG extend=1 "; shift;;
131 -g) gnuplot=1; shift;;
132 -l) paper=1; para=$para"$AVARFLAG paper=1 "; shift;;
133 -p) gnuplot=0; shift;;
136 if test "$#" -eq 0; then
137 _ '%s: no argument for -t option\n' $0 1>&2
140 maxtime="$1"; shift;;
144 if [ $# -eq 0 ] ; then
145 _ '%s: no input files\n' $0 1>&2
148 para=$para"$AVARFLAG maxtime=$maxtime"
150 if [ $gnuplot -eq 1 ] ; then
151 my_plot=$my_plot"p" # use the plot prog that pauses
152 plot=" -geometry 800x700+40+0"
153 para=$para"$AVARFLAG gnuplot=1 "
154 _ "Displaying graph on the screen, <CR> for next graph"
156 if [ "$paper" -eq 1 ] ; then
157 _ '%s: -l requires -p flag at the same time\n' $0 1>&2
160 if [ "$bw" -eq 1 ] ; then
161 _ '%s: -b requires -p flag at the same time\n' $0 1>&2
166 if [ $bw -eq 1 ]; then
170 list=""; # files to compress at the end
172 for i in ${1+"$@"} # for all the input files
175 if [ ! -f "$f" ] ; then
176 f=`ls "$i" "$i".*[zZ] 2>/dev/null`
178 if [ -f "$f" ] ; then # found file
179 disp=`$AWK -f $amlibexecdir/amcat.awk $AVARFLAG f="$f"`
180 if [ -z "$disp" ] ; then
181 _ 'Do not know how to [gz|z]cat this file\n'
183 /bin/rm -f $tmp_files
184 $disp "$f" | $AWK -f $amlibexecdir/amplot.awk $para
185 $GNUPLOT $plot $my_plot
186 if [ $disp = "cat" -a $cmpres -eq 1 ] ; then
190 else # check if file has been compressed
191 _ 'No such file %s or %s\n' "$i" "$i.*[zZ]"
195 /bin/rm -f $tmp_files
197 if [ "$list" != "" ] ; then # now compress the files we worked on
198 # comment out next line if you do not want compression at the end
199 _ 'Compressing %s\n' "$list"