Skip to content

Instantly share code, notes, and snippets.

@chrisice
Created October 9, 2014 20:22
Show Gist options
  • Save chrisice/78c0911fa90ee657745b to your computer and use it in GitHub Desktop.
Save chrisice/78c0911fa90ee657745b to your computer and use it in GitHub Desktop.
Get document root
#!/usr/bin/perl
my $input = $ARGV[0];
if ($input !~ /.*@.*/) {
print "Please enter a valid email address.\n";
die("\n");
}
else{
($user, $domain) = $ARGV[0] =~ /(.*)@(.*)/;
my %used;
my $string = 'grep -3';
my $domainstring = "www.$domain";
my $lookupfile = '/usr/local/apache/conf/httpd.conf';
@lines = qx/$string $domainstring $lookupfile/;
@stuff = grep( /.*$domianstring.*/, @lines);
@stuff = grep(/^.+?(\/.+\/.+$)/, @stuff);
$numlines = scalar(grep {defined $_} @stuff);
if ( $numlines != 1 ) {
pop @stuff;
foreach $stuff (@stuff) {
print $1 if $stuff =~ m/(\/.*$)/;
print "\n";
}
}
else {
foreach (@stuff) {
print $_;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment