/[vz-tools]/trunk/lib/VZ.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/lib/VZ.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 38 - (hide annotations)
Fri Feb 8 21:45:37 2008 UTC (16 years, 2 months ago) by dpavlin
File size: 472 byte(s)
- make own hostname2ip instead of using host command
- restart using sudo if needed
1 dpavlin 38 package VZ;
2     use Exporter 'import';
3     our @EXPORT = qw(
4     check_root
5     hostname2ip
6     );
7    
8     use warnings;
9     use strict;
10    
11     use Socket;
12    
13     sub check_root {
14     if ( $> != 0 ) {
15     warn "WARNING: restarting as root using sudo\n";
16     exec 'sudo', $0, @ARGV;
17     }
18     }
19    
20     sub hostname2ip {
21     my $hostname = shift || return;
22    
23     my @addresses = gethostbyname($hostname) or die "Can't resolve $hostname: $!\n";
24     @addresses = map { inet_ntoa($_) } @addresses[4 .. $#addresses];
25     return shift @addresses;
26     }
27    
28     1;

  ViewVC Help
Powered by ViewVC 1.1.26