-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenhost.pl
executable file
·80 lines (62 loc) · 1.46 KB
/
genhost.pl
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
#!/usr/bin/perl -w
#
# $Id: genhost.pl,v 1.5 2008/01/09 19:40:38 steve Exp $
use strict;
use warnings;
my $host=shift;
if (!$host) {
print STDERR "Usage: genhost.pl <hostname>\n";
exit 1;
}
my @fs;
#open(DF, "ssh $host df |");
#while (<DF>) {
# my @foo=split;
# push(@fs, $foo[$#foo]) if ($foo[0]=~/^\/dev\// and $foo[$#foo] ne "/tmp");
#}
#close(DF);
my @df=`ssh $host df` or die "Failed to run df: $!\n";
shift @df;
for (my $n=0;$n<@df;$n++) {
chomp $df[$n];
if ($df[$n]=~/^\s/) {
$df[$n-1].=$df[$n];
splice(@df,$n,1);
$n--;
}
}
for my $n (@df) {
my @foo=split ' ', $n;
push(@fs, $foo[$#foo]) if ($foo[0]=~/^\/dev\// and $foo[$#foo] ne "/tmp");
}
print "# filesystem\tcommand\n";
for my $fs (@fs) {
print "$fs";
my @children=&find_children($fs, @fs);
if (@children) {
print "\tDEFAULT";
for my $child (@children) {
print " --exclude $child";
}
}
print "\n";
}
sub find_children {
my ($fs, @fs)=@_;
my @children;
for my $child (@fs) {
next if ($child eq $fs);
if ($child=~/^$fs\// or $fs eq "/") {
$child=~s/^$fs//;
$child="/$child/";
$child=~s,^//+,/,;
$child=~s,//+$,/,;
push(@children, $child);
}
}
for (my $n=0;$n<@children;$n++) {
@children=grep { $_ eq $children[$n] or !/^$children[$n]/ } @children;
}
return @children;
}
# vi: set ai et: