This file is indexed.

/usr/sbin/amtoc is in amanda-server 1:3.3.6-4.

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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/perl -w

# create a TOC (Table Of Content) file for an amanda dump

# Author: Nicolas.Mayencourt@cui.unige.ch

# release 3.1.4

# HISTORY
# 1.0 19??-??-?? nicolas@cui.unige.ch
#	don't remember :-)
# 2.0 1996-??-?? nicolas@cui.unige.ch
#	amanda 2.2.6 support
# 3.0 1999-02-17 Nicolas.Mayencourt@cui.unige.ch
#	major rewrite, incompatible with release 2.0, amanda 2.4 support
# 3.0.1 1999-02-17 oliva@dcc.unicamp.br
#	minor fixes for multi-tape runs
# 3.0.2 1999-02-28 martineau@IRO.UMontreal.CA
#	output the datestamp of each dump
# 3.0.3 1999-09-01 jrj@purdue.edu
#	allow multiple -s entries
# 3.0.4 1999-09-15 jrj@purdue.edu
#	handle an image failing on one tape...
# 3.1.0 1999-10-06 Nicolas.Mayencourt@cui.unige.ch
#	add new options (-i -t)
# 3.1.1 1999-10-08 Nicolas.Mayencourt@cui.unige.ch
#	print original size, instead of size-on-tape
# 3.1.2 1999-10-11 Nicolas.Mayencourt@cui.unige.ch
#	really print original size, instead of size-on-tape
# 3.1.3 Nicolas.Mayencourt@cui.unige.ch
#	correct a bug for total report
# 3.1.4 2000-01-14 dhw@whistle.com
#	Add a flag (-w) for vertical whitespace


#--------------------------------------------------------
sub pr($$$$$$$) { 
# you can update these proc if you want another formating
# format: filenumber  host:part  date  level  size
# If you use tabular option, modifie the format at the end of the code
  if (defined($tabular)) {
	$fnbr=$_[0];
	$hstprt=$_[1] . ":" . $_[2];
	$dt=$_[3];
	$lvl=$_[4];
	$sz=$_[5];
	$ch=$_[6];
    write($OF);
  } else {
    print $OF "$_[0]  $_[1]:$_[2]  $_[3]  $_[4]  $_[5]  $_[6]\n";
  }
}
#--------------------------------------------------------



#--------------------------------------------------------
sub tfn($) {
  # calculate tocfilename
  $_ = $_[0];
  foreach $s (@subs) {
    eval $s;
  }
  return $dir . $_ ;
}
#--------------------------------------------------------


#--------------------------------------------------------
sub usage($) {
  print STDERR "@_\n\n";
  print STDERR "usage: amtoc [-a] [-i] [-t] [-f file] [-s subs] [-w] [--] logfile\n";
  print STDERR "         -a      : file output to `label`.toc\n";
  print STDERR "         -i      : Start TOC with a small help message\n";
  print STDERR "         -t      : tabular output\n";
  print STDERR "         -f file : output to file\n";
  print STDERR "         -s subs : output file name evaluated to `eval \$subs`\n";
  print STDERR "         -w      : add vertical whitespace after each tape\n";
  print STDERR "         --      : last option\n";
  print STDERR "         logfile : input file ('-' for stdin)\n";
  exit;
}
#--------------------------------------------------------

#--------------------------------------------------------
sub init() {
  &usage("amtoc required at least 'logfile' parameter.") if ($#ARGV==-1) ;

  @subs = ();
  for ($i=0;$i<=$#ARGV;$i++) {
    if ($ARGV[$i] eq '-a') {
        push (@subs, "s/\$/.toc/");
      }
    elsif ($ARGV[$i] eq '-i') {
        $info=1;
      }
    elsif ($ARGV[$i] eq '-t') {
        $tabular=1;
      }
    elsif ($ARGV[$i] eq '-f') {
        $i++;
        &usage("'-f' option require 'file' parameter.")  if ($i > $#ARGV);
        $tocfilename=$ARGV[$i];
      }
    elsif ($ARGV[$i] eq '-s') {
        $i++;
        &usage("'-s' option require 'subs' parameter.")  if ($i > $#ARGV);
        push (@subs, $ARGV[$i]);
      }
    elsif ($ARGV[$i] eq '-w') {
        $vwspace=1;
      }
    elsif ($ARGV[$i] eq '--') {
      # no more options: next arg == logfile
        $i++;
        &usage("amtoc required at least 'logfile' parameter.") if ($i > $#ARGV);
        $logfile=$ARGV[$i];
        &usage("too many parameters.") unless ($i == $#ARGV);
      }
    else {
        $logfile=$ARGV[$i];
        &usage("too many parameters.") unless ($i == $#ARGV);
      }
  }
  &usage("amtoc required at least 'logfile' parameter.") unless ($logfile);
}

#--------------------------------------------------------

&init;

delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
$ENV{'PATH'} = "/usr/bin:/usr/sbin:/sbin:/bin";

$dir=$logfile;
$dir =~ s/[^\/]*$//;


if ($logfile eq '-') {$IF=STDIN} else 
  {die ("Cannot open logfile $logfile") unless open (IF,"$logfile");$IF=IF;}

$filenumber=0;
$tot_or_size=0;

while ( <$IF> ) {
  $line = $_;
  if ( /^FAIL dumper (\S+) (\S+)/ ) {
    next;
  }
  if ( /^SUCCESS dumper (\S+) (\S+)/ ) {
    $host = $1;
    $disk = $2;
    $line =~ /orig-kb (\d+)/;
    $osize{$host}{$disk} = $1;
    $tot_or_size += $osize{$host}{$disk};
    $fail{$host}{$disk} = 0;
    next;
  }
  if ( /^START amflush/ ) {
    $flash_mode = 1;
    next;
  }
  if ( ! /^([A-Z]+) taper (\S+) (\S+) (\S+) (\S+) (\S+)/) { next;}
  # $_ = $1;
  if (/PART taper/) {
    /^([A-Z]+) taper (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)/;
    $filenum = $3;
    $host = $4;
    $disk = $5;
    $date = $6;
    $chunk = $7;
    $level = $8;
    if ($filenum != $filenumber) {
      # This should not be possible */
      $filenumber = $filenum;
    }
  } else {
    /^([A-Z]+) taper (\S+) (\S+) (\S+) (\S+) (\S+)/;
    $host = $2;
    $disk = $3;
    $date = $4;
    $chunk = $5;
    $level = $6;
  }
  switch: {
    /START taper/ && do {
      $tocfilename=&tfn($chunk) if ($#subs >= 0);
      if (!$tocfilename || ($tocfilename eq '-')) {$OF=STDOUT;}
      else {
          die ("Cannot open tocfile $tocfilename") unless open(OF,">$tocfilename");
          $OF=OF;
        }

	print $OF "\f" if ($vwspace && $filenumber);
	if (defined($info)) {
	  print $OF "AMANDA: To restore:\n";
	  print $OF "    position tape at start of file and run:\n";
	  print $OF "        dd if=<tape> bs=32k skip=1 [ | zcat ] | restore -...f\n";
	  print $OF "    or run: amrestore -p <tape> [host [partition]] | restore -...f\n";
	  print $OF "\n";
	}



      $filenumber=0;
      &pr("#","Server","/partition","date", "level","size[Kb]","part");
      &pr("$filenumber","$chunk","","$disk","-","-","-");
      last switch; };
    /^(?:SUCCESS|CHUNK|PART|DONE) taper/ && do {
      if(/SUCCESS/){
	$level = $chunk;
	$chunk = "-";
      }
      $filenum = $filenumber;
      if (/DONE/) {
	$chunk = "-";
	$filenumber--;
	$filenum = " ";
      }
      $mysize = 0;
      if(/ kb (\d+) /){
	$mysize = $1;
      }
      if ( $fail{$host}{$disk} ) {
        &pr("$filenum","${host}","${disk}","${date}","${level}","FAIL","${chunk}");
      } else {
  	if (defined($flash_mode)) {
          &pr("$filenum","${host}","${disk}","${date}","${level}","$mysize","${chunk}");
	} else {
  	  if (defined($osize{$host}{$disk}) && !/^CHUNK/ && !/^PART/) {
            &pr("$filenum","${host}","${disk}","${date}","${level}","$osize{$host}{$disk}","${chunk}");
	  } else {
	    $note = "";
	    if(!/^CHUNK/ && !/^PART/){
		# this case should never happend: 
	    } else {
	      $note = "*";
	    }
            &pr("$filenum","${host}","${disk}","${date}","${level}","$note$mysize","${chunk}");
	  }
	}
      }
      last switch;};
    /INFO taper retrying/ && do {
      --$filenumber;
      last switch; };
    /INFO taper tape .* \[OK\]/ && do {
      $line =~ / kb (\d+) /;
      $size = $1;
      $line =~ / fm (\d+) /;
      print "\n\n" if ($vwspace);
      &pr("$1","total","on_tape","-","-","$size","-");
      last switch; };
    /FAIL taper/ && do { next; };
  }
  $filenumber += 1;
}
if (defined($flash_mode)) {
  &pr("-","total","origin","-","not","available","-");
} else {
  &pr("-","total","origin","-","-","$tot_or_size","-");
}
close $IF;
close OF;


format OF =
@>>  @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @>> @>>>>>>>>
$fnbr,$hstprt,$dt,$lvl,$sz
.

format STDOUT =
@>>  @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<< @>> @>>>>>>>> @>>>
$fnbr,$hstprt,$dt,$lvl,$sz,$ch
.