#!/usr/bin/perl -w # # df Act like UNIX df utility # usage: run df.pl and follow the text # use Net::Ping; use Net::OpenSSH; use IO::Socket; my ($ssh, $rsh) = qw(22 514); while (1) { print "nom du serveur: "; chomp(my $server = ); die "le nom du serveur est obligatoire\n" unless $server; print "nom du FS sans le premier / : "; chomp(my $fs = ); die "le nom du FS est obligatoire\n" unless $fs; sub os_port { foreach (@_) { $sock = new IO::Socket::INET(PeerAddr => $server, PeerPort => $_, Proto => 'tcp'); last if $sock; } $sock; } my $p = Net::Ping->new; #new("icmp") if ($p->ping($server)) { my $sock = os_port($ssh, $rsh); die "Aucune possibilite a se connecte au serveur\n" unless $sock; while (<$sock>) { $sock_string = $_; last; } close $sock; } $p->close(); if ($sock_string) { my $openssh = Net::OpenSSH->new($server); $openssh->error and die "Couldn't establish SSH connection: ". $openssh->error; chomp(my $uname = $openssh->capture("uname -s")); $openssh->error and die "remote uname command failed: " . $openssh->error; if ($uname =~ /Linux/) { $openssh->system("df -h /$fs") or die "remote command failed: " . $openssh->error; } elsif ($uname =~ /AIX/) { $openssh->system("df -m /$fs") or die "remote command failed: " . $openssh->error; } elsif ($uname =~ /HP-UX/) { $openssh->system("bdf /$fs") or die "remote command failed: " . $openssh->error; } else { $openssh->system("df /$fs") or die "remote command failed: " . $openssh->error; } } else { system "rsh $server bdf /$fs"; } }