/[BackupPC]/trunk/xls2conf/xls2conf.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/xls2conf/xls2conf.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (hide annotations)
Mon Jul 11 16:22:50 2005 UTC (18 years, 10 months ago) by dpavlin
File MIME type: text/plain
File size: 2718 byte(s)
fixed names, Makefile and misc stuff

1 dpavlin 22 #!/usr/bin/perl -w
2    
3     use strict;
4     use Spreadsheet::ParseExcel;
5    
6     my $xls_file = shift @ARGV || die "usage: $0 file.xls\n";
7    
8     my $oBook = Spreadsheet::ParseExcel::Workbook->Parse($xls_file);
9    
10     # BackupPC hosts file
11     my %bpc_hosts;
12     my %hosts;
13     my %smb_share_name;
14    
15     foreach my $sheet (@{$oBook->{Worksheet}}) {
16     if ($sheet->{Name} !~ m/Instruments/i) {
17     # print "# skipped sheet ",$sheet->{Name},"\n";
18     next;
19     }
20     for(my $i = $sheet->{MinRow} ; defined $sheet->{MaxRow} && $i <= $sheet->{MaxRow} ; $i++) {
21     # IP
22     my $id = $sheet->{Cells}[$i][3]->{Val} || next;
23     my $ime = $sheet->{Cells}[$i][4]->{Val} || next;
24    
25     my $conf_name = lc($ime . '_' . $id);
26     $conf_name =~ s/\s+/_/g;
27    
28     my $ip = $sheet->{Cells}[$i][16]->{Val} || next;
29     my $hostname = $sheet->{Cells}[$i][17]->Value || next;
30     my $os = $sheet->{Cells}[$i][19]->Value || next;
31     my $path = $sheet->{Cells}[$i][23]->Value || next;
32     my $share = $sheet->{Cells}[$i][24]->Value || next;
33    
34     if ($ip !~ /\d+\.\d+\.\d+\.\d+/) {
35     print "# skipped $ip, $hostname, $os, $path, $share\n";
36     next;
37     }
38    
39     print "$ip hostname[$hostname] os[$os] path[$path] share[$share]\n";
40    
41     my $drive = lc(substr($path,0,1));
42    
43     my $rsync_share;
44     if ($drive eq 'c') {
45     $rsync_share = 'cDrive';
46     } elsif ($drive eq 'd') {
47     $rsync_share = 'dDrive';
48     } else {
49     die "unknown drive '$drive' from path '$path'";
50     }
51    
52     $path =~ s#^[cd]:\\#/#gi;
53     $path =~ s#\\#/#g;
54    
55     open(O, "> conf/${conf_name}.pl") || die "can't open ${conf_name}.pl";
56    
57     if ($os =~ m#(98|95)#) {
58    
59     print "$ip\tsmb://${share}\n";
60    
61     push @{$smb_share_name{$hostname}}, $share;
62    
63     print O qq`
64     # $ip $os
65     \$Conf{XferMethod} = 'smb';
66     \$Conf{SmbHostName} = '$hostname';
67     \$Conf{SmbShareName} = [ '`,join("','", @{$smb_share_name{$hostname}}),qq`' ];
68     `;
69    
70     if ($hosts{$ip}) {
71     $hosts{$ip} .= "\t$hostname" unless ($hosts{$ip} =~ m/$hostname/i);
72     } else {
73     $hosts{$ip} = "$ip\t$hostname";
74     }
75     } else {
76    
77     print "$ip\trsync://${share}::${path}\n";
78    
79     $path =~ s/([ '])/\\$1/g;
80    
81     print O qq`
82     # $ip $os
83     \$Conf{XferMethod} = 'rsyncd';
84     \$Conf{RsyncShareName} = [ '$rsync_share' ];
85     \$Conf{BackupFilesOnly} = [ '$rsync_share' => "$path" ];
86     `;
87    
88     }
89    
90     close(O);
91    
92     $bpc_hosts{$conf_name} = "$conf_name\t0\tasa";
93     if ($hosts{$ip}) {
94     $hosts{$ip} .= "\t$conf_name" unless ($hosts{$ip} =~ m/$conf_name/i);
95     $hosts{$ip} .= "\t$hostname" unless ($hosts{$ip} =~ m/$hostname/i);
96     } else {
97     $hosts{$ip} = "$ip\t$conf_name\t$hostname";
98     }
99     }
100    
101     }
102    
103     open(H, "> conf/hosts.backuppc") || die "hosts.backuppc $!";
104     foreach my $k (sort keys %bpc_hosts) {
105     print H $bpc_hosts{$k},"\n";
106     }
107     close(H);
108    
109     open(H, "> conf/hosts.add") || die "hosts.add $!";
110     foreach my $k (sort keys %hosts) {
111     print H $hosts{$k},"\n";
112     }
113     close(H);

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26