2 # Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 # Copyright (c) 1992-1998 University of Maryland at College Park
4 # Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
7 # Permission to use, copy, modify, distribute, and sell this software and its
8 # documentation for any purpose is hereby granted without fee, provided that
9 # the above copyright notice appear in all copies and that both that
10 # copyright notice and this permission notice appear in supporting
11 # documentation, and that the name of U.M. not be used in advertising or
12 # publicity pertaining to distribution of the software without specific,
13 # written prior permission. U.M. makes no representations about the
14 # suitability of this software for any purpose. It is provided "as is"
15 # without express or implied warranty.
17 # U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19 # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 # Author: Olafur Gudumundsson, (ogud@tis.com) Trusted Information Systems
25 # Formerly at: Systems Design and Analysis Group
26 # Computer Science Department
27 # University of Maryland at College Park
29 # Amplot: a program to generate postscript plots of each nights amanda
32 # Author: Olafur Gudmundsson (ogud@tis.com)
33 # Creation Date: April 1992
34 # Last modified: April 1995
35 # Input: list of amdumps
36 # Output: Plot of amdump files as either gnuplots on the screen or
41 exec_prefix="@exec_prefix@"
43 amlibexecdir="@amlibexecdir@"
44 . "${amlibexecdir}/amanda-sh-lib.sh"
48 # add sbin and ucb dirs
49 PATH="$PATH:/usr/sbin:/sbin:/usr/ucb"
52 # we use a different version of the compression variable than amanda itself.
53 COMPRESS=@AMPLOT_COMPRESS@
55 # Function to check that awk can do command-line variable
56 # substitution. If no, then exit; if yes, set $AVARFLAG
57 # to the commandline switch used to introduce a variable. This
58 # check used to be performed at build time in configure; it's
59 # now performed at runtime.
62 tmpfile=`mktemp /tmp/amplot.XXXXXX`
63 echo 'BEGIN{print i; exit}' > ${tmpfile}
64 result=`$AWK -f ${tmpfile} i=xx | wc -c`
65 if test "$result" -le 1; then
66 result=`$AWK -f ${tmpfile} -v i=xx | wc -c`
67 if test "$result" -le 1; then
68 echo "$AWK does not support command-line variable assignment; amplot cannot run" >&2
81 # Function to search for gnuplot and ensure it's working. This
82 # first tries the location detected/configured when amanda was built,
83 # then tries 'gnuplot', assuming it's in the user's path. If no
84 # working gnuplot executable is found, it exits with an error. The
85 # variable $GNUPLOT is set to the resulting executable.
87 if test "x$GNUPLOT" = "x"; then
88 # look for it in the user's PATH
92 if ${GNUPLOT} --version 2>/dev/null | grep '^gnuplot' >/dev/null; then
95 echo "${GNUPLOT} was not found; amplot cannot run"
100 # check our environment, using functions from above
104 if [ $# -eq 0 ] ; then
105 _ 'Usage: %s [-c] [-e] [-g] [-l] [-p] [-t hours] <amdump_files.[gz,z,Z]>\n' $0
106 _ '%s generates plot for screen with fixed dimensions\n' $0
107 _ ' -c Compress the input amdump files after plotting\n'
108 _ ' -e Extends x (time) axes if needed\n'
109 _ ' -g Run gnuplot directly no postscript file generated DEFAULT\n'
110 _ ' -l Landscape mode suitable for printing\n'
111 _ ' -p Postscript output (color)\n'
112 _ ' -b The postscipt will be b/w\n'
113 _ ' -t T Set the right edge of the plot to be T hours\n'
117 tmp_files="bandw_free disk_alloc dump_idle finished run_queue tape_* title"
119 my_plot=$amlibexecdir/amplot.g
127 # setting up the parameters to pass to [gn]awk
130 -c) cmpres=1; shift;;
131 -e) para=$para"$AVARFLAG extend=1 "; shift;;
132 -g) gnuplot=1; shift;;
133 -l) paper=1; para=$para"$AVARFLAG paper=1 "; shift;;
134 -p) gnuplot=0; shift;;
137 if test "$#" -eq 0; then
138 _ '%s: no argument for -t option\n' $0 1>&2
141 maxtime="$1"; shift;;
145 if [ $# -eq 0 ] ; then
146 _ '%s: no input files\n' $0 1>&2
149 para=$para"$AVARFLAG maxtime=$maxtime"
151 if [ $gnuplot -eq 1 ] ; then
152 my_plot=$my_plot"p" # use the plot prog that pauses
153 plot=" -geometry 800x700+40+0"
154 para=$para"$AVARFLAG gnuplot=1 "
155 _ "Displaying graph on the screen, <CR> for next graph"
157 if [ "$paper" -eq 1 ] ; then
158 _ '%s: -l requires -p flag at the same time\n' $0 1>&2
161 if [ "$bw" -eq 1 ] ; then
162 _ '%s: -b requires -p flag at the same time\n' $0 1>&2
167 if [ $bw -eq 1 ]; then
171 list=""; # files to compress at the end
173 for i in ${1+"$@"} # for all the input files
176 if [ ! -f "$f" ] ; then
177 f=`ls "$i" "$i".*[zZ] 2>/dev/null`
179 if [ -f "$f" ] ; then # found file
180 disp=`$AWK -f $amlibexecdir/amcat.awk $AVARFLAG f="$f"`
181 if [ -z "$disp" ] ; then
182 _ 'Do not know how to [gz|z]cat this file\n'
184 /bin/rm -f $tmp_files
185 $disp "$f" | $AWK -f $amlibexecdir/amplot.awk $para
186 $GNUPLOT $plot $my_plot
187 if [ $disp = "cat" -a $cmpres -eq 1 ] ; then
191 else # check if file has been compressed
192 _ 'No such file %s or %s\n' "$i" "$i.*[zZ]"
196 /bin/rm -f $tmp_files
198 if [ "$list" != "" ] ; then # now compress the files we worked on
199 # comment out next line if you do not want compression at the end
200 _ 'Compressing %s\n' "$list"