This file is indexed.

/usr/bin/byobu-ugraph is in byobu 5.77-0ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
#---------------------------------------------------------------------
# Script to display a byobu notification "history graph".
#
# Designed to work with the wonderful byobu(1) but can be run
# stand-alone.
#---------------------------------------------------------------------
#
# Copyright (C) 2011 Canonical Ltd.
#
# Author: James Hunt <james.hunt@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#---------------------------------------------------------------------

PKG="byobu"
[ -r "$HOME/.byoburc" ] && . "$HOME/.byoburc"
[ -z "${BYOBU_PREFIX}" ] && export BYOBU_PREFIX="/usr" || export BYOBU_PREFIX
. "${BYOBU_PREFIX}/lib/${PKG}/include/common"

script_name=${0##*/}
min_default=0
max_default=100
points_default=5
theme_default=vbars_8
newline="\n"
rotate=y

error()
{
  msg="$*"
  echo "ERROR: $msg" >&2
}

die()
{
  error "$*"
  exit 1
}

usage()
{
cat <<EOT
Description: Display a graph of historical indicator values using
             byobu-ulevel.

Usage: $script_name [options] [command [args...]]

Options:

 -f <file>   : File to read data points from.
               (only required if no command specified).
 -h          : Show this help.
 -m <num>    : Minimum value (default=$min_default).
 -n          : Supress output of newline character.
 -p <points> : Specify number of data points in graph
               (default=$points_default).
 -r          : Do not rotate file <file> (default is to rotate).
               Option implies file <file> should not be written to
               so a command cannot follow script options in this case.
 -t <theme>  : 'byobu-ulevel' theme to use (default=$theme_default).
 -x <num>    : Maximum value (default=$max_default).


Examples:

  Using $script_name to run a command, rotate log and display graph.

  Here we specify a command to display available memory.
  Trailing echo adds a required newline
  Note no filename specified.

    $script_name "(/usr/lib/byobu/mem_used | sed -e 's/% //g';echo)"


  Using $script_name just to rotate log and display the graph

    file=/tmp/load.dat
    awk '{ print \$1}' /proc/loadavg >> \$file
    # Note: we need to specify what we consider to be a "reasonable" maximum load
    $script_name -m 3.0 -f \$file

Notes:

  - If you specify 'command', care must be taken with shell quoting to
    avoid expansion prior to this script running the command.
  - If '-r' is not specified, the file <file> will be rotated such that
    at most <points> lines are retained on each invocation of this
    script.

EOT
}

get_data()
{
  needed_lines=$points

  if [ ! -f $file ]
  then
    return
  fi

  lines=$(wc -l $file|awk '{print $1}')

  if [ $lines -lt $needed_lines ]
  then
    # insufficient data
    return
  fi

  bytes=$(<${file})
  bytes=$(echo "$bytes"|tail -n ${needed_lines})
  [ $lines -eq $needed_lines -o $rotate = n ] && echo "$bytes" && return

  # rotate
  tmp=`tempfile`
  echo "$bytes" > $tmp
  mv $tmp $file

  echo "$bytes"
}

while getopts "f:hm:np:rt:x:" opt
do
  case "$opt" in
    f)
      file="$OPTARG"
    ;;

    h)
      usage
      exit 0
    ;;

    m)
      min=$OPTARG
    ;;

    n)
      newline=
    ;;

    p)
      points=$OPTARG
    ;;

    r)
      rotate=n
    ;;

    t)
      theme="$OPTARG"
    ;;

    x)
      max=$OPTARG
    ;;
  esac
done

shift $[$OPTIND-1]

cmd="$@"

[ -z "$theme" ] && theme=$theme_default

if [ -z "$cmd" ]
then
  if [ -z "$file" ]
  then
    error "must specify file"
    usage
    exit 1
  fi
fi

if [ -z "$file" ]
then
  # we could go cryptic+safe by calling tempfile(1), but that then
  # makes it very difficult to find in case of need.
  file=/tmp/${USER}-${script_name}-$$.dat
fi

[ -z "$min" ]    && min=$min_default
[ -z "$max" ]    && max=$max_default
[ -z "$points" ] && points=$points_default

if [ ! -z "$cmd" ]
then
  if [ $rotate = n ]
  then
    error "cannot write to file if rotate disabled"
    usage
    exit 1
  fi

  eval "$cmd >>$file"
fi

data=$(get_data)

[ -z "$data" ] && printf "%*.s${newline}" $points && exit 0

for datum in $data
do
  byobu-ulevel -n -m $min -x $max -p -c $datum -t $theme
done