quick and dirty host-locking in perl

Version 1
    Share:|

    Here's a snippet of code to only run a certain perl script if it's running on the right host (say, if you're running some legacy perl script, and the underlying infrastructure for it only exists on one host....)

     

     

     

     

    #!/usr/bin/perl

    use Sys::Hostname;
    $host = hostname;


    print "My hostname is $host\n";

    if ( $host eq "somehost.bmc.com" ) {
      print "This host is somehost.bmc.com, continuing!\n";
    } else {
      print "Not the right host, bailing out!\n";
    }