Parent Directory | Revision Log
- make own hostname2ip instead of using host command - restart using sudo if needed
1 | 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 |