http://www.perlmonks.org?node_id=924453

Having to support many different UNIX platforms is a challenge and a pain in the same time. What commands should I run on each of them for a trivial checkup ? What are the options should I use ? etc. So I came up with a script for the abstraction purposes, where the only think I need is the hostname and the <thing> to check. Because originally this was spin around the FS usage I wrote for this functionality. Now I think it may be expanded to something more generic, but till then I wild like to share it, cause - I find it cool to use.
#!/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 = <STDIN>); die "le nom du serveur est obligatoire\n" unless $server; print "nom du FS sans le premier / : "; chomp(my $fs = <STDIN>); 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 $so +ck; 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->err +or; 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"; } }
Here it is - AIX, HP-UX and Linux platforms via SSH or Rlogin connections acting as expected in each and every case.