summaryrefslogtreecommitdiff
path: root/lib/hostname.pl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/hostname.pl')
-rw-r--r--lib/hostname.pl23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/hostname.pl b/lib/hostname.pl
new file mode 100644
index 0000000000..5394c6ec69
--- /dev/null
+++ b/lib/hostname.pl
@@ -0,0 +1,23 @@
+# From: asherman@fmrco.com (Aaron Sherman)
+
+sub hostname
+{
+ local(*P,@tmp,$hostname,$_);
+ if (open(P,"hostname 2>&1 |") && (@tmp = <P>) && close(P))
+ {
+ chop($hostname = $tmp[$#tmp]);
+ }
+ elsif (open(P,"uname -n 2>&1 |") && (@tmp = <P>) && close(P))
+ {
+ chop($hostname = $tmp[$#tmp]);
+ }
+ else
+ {
+ die "$0: Cannot get hostname from 'hostname' or 'uname -n'\n";
+ }
+ @tmp = ();
+ close P; # Just in case we failed in an odd spot....
+ $hostname;
+}
+
+1;