13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 4 ■ TAKING BACKUPS AND MANAGING DATA01 #!/usr/bin/perl -w02 # Script to tally up total disk space available and used in local network03 # JK 25.03.20090405 use strict;06 use Net::LDAPS;0708 die "Usage: dfscript\n" unless @ARGV == 0;0910 my ($search) = @ARGV;11 my $server = "ldaps://ldap.example.com";12 my $cert = "/etc/ldap/servercert.pem";13 my $base = "dc=example,dc=com";14 my $total = 0;15 my $used = 0;1617 my $ldap = Net::LDAPS->new( $server,18 verify => 'optional',19 cafile => $cert ) or die $@;20 my $mesg = $ldap->bind;21 my $filter = "(objectClass=ipHost)";22 $mesg = $ldap->search( base => $base,23 filter => $filter,24 attr => ['cn'],25 );26 $mesg->code && die $mesg->error;2728 my @entries = $mesg->sorted('cn');2930 foreach my $entry ( @entries ) {31 my $machine = $entry->get_value( 'cn' );32 if ( $machine ) {33 open my $info, '-|', "ssh $machine 'df'"34 or warn "Can't ssh to $machine";36 while () {37 if ( /^\/dev/ ) {38 my @list = split;39 $total += $list[1];40 $used += $list[2];41 }42 }43 }44 }4546 $mesg = $ldap->unbind;47 print "Total is: $total\nUsed is: $used\n";97Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!