Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Find installed Perl interpreters (shell script!)

by crenz (Priest)
on Aug 01, 2002 at 13:22 UTC ( [id://186772]=sourcecode: print w/replies, xml ) Need Help??
Category: CGI Programming
Author/Contact Info Christian Renz <crenz at web42.com>
Description:

Okay -- this is a shell script, so there's not much to be learned in terms of perl programming. However, I think it can be very helpful if you have an account at one of those cheap providers that allow CGI, but no shell, and you have trouble finding all the perl interpreters and their library paths.

See a demo at http://www.web42.com/software/findperl/findperl.cgi

(Note to Editor: If you deem it inappropriate for perlmonks.com, please feel free to delete).

#!/bin/sh

# (c) Christian Renz <crenz@web42.com?
# http://www.web42.com/software/findperl/

### Configuration ###

# Add a path here (e.g. /usr/bin/locate) if you run into problems
LOCATE=locate
WHICH=which
UNAME=uname
GREP=grep

# Shell-Expression for perl interpreter filenames (for locate)
PERLSHEX='perl'

# Regex for perl interpreter filenames (for grep)
PERLREGEX='/perl[0-9.]*$'

# perl interpreter filenames (for which and manual search)
PERLNAMES='perl perl5 perl4'

# Fallback paths if locate and which fail
FALLBACK='/usr/bin /usr/local/bin /bin /opt/bin'

# Error formatting
RED='<font color="#C00000"><b>'
NORED='</font></b>'

### Main Program ###

# echo nice HTML layout
echo 'Content-Type: text/html

<html>
<head>
<title>findPerl</title>
</head>

<p>&nbsp;</p>
<blockquote>
<h2>findPerl</h2>
<hr size="1" width="100%">
'

# find out some system information

SYSINFO=`$UNAME -a`

if [ -z "$SYSINFO" ]; then
    echo "<p>$RED No system information found: $UNAME failed $NORED </
+p>"
else
    echo "<p><b>System information (retrieved using <tt>$UNAME</tt>)</
+b>:
$SYSINFO</p>"
fi

### Searching for Perl ###

echo "<p>Searching for perl interpreters installed on your
system. This may take a few seconds.</p><p>"

# Using locate...
METHOD="<tt>$LOCATE</tt> / <tt>$GREP</tt>"
PERLFOUND=`$LOCATE "$PERLSHEX" | $GREP "$PERLREGEX"`

# Using which...
if [ -z "$PERLFOUND" ]; then
    echo "<p>$RED $METHOD failed. $NORED Using <tt>$WHICH</tt> instead
+.<p>"

    METHOD="<tt>$WHICH</tt>"

    for i in $PERLNAMES; do
#       echo "Searching for '$i'...<br>"
        THISFOUND=`$WHICH $i`

        if [ "$THISFOUND" ]; then
            PERLFOUND="$PERLFOUND $THISFOUND"
        fi
    done
fi

# Using fallback paths...

if [ -z "$PERLFOUND" ]; then
    echo "<p>$RED $METHOD failed. $NORED Using search in <tt>$FALLBACK
+</tt>
instead.</p>"

    METHOD="search in <tt>$FALLBACK</tt>"

    for i in $FALLBACK; do
        for j in $PERLNAMES; do
            PERLFOUND="$PERLFOUND $i/$j"
        done
    done
fi

### Find real perl interpreters ###

REALPERL=''

# $PERLFOUND probably contains some paths, man pages etc.
# We are only interested in those files which are standard 
# files and executable
for i in $PERLFOUND; do
    if [ -f "$i" -a -x "$i" ]; then
        REALPERL="$REALPERL $i"
    fi
done

### Output information about perl interpreters ###

if [ -z "$REALPERL" ]; then
    echo "<p>$RED Sorry, I was unable to find any perl
interpreter.$NORED Probably something went horribly wrong. Contact you
+r
server administrator for assistance.</p>"
else
    echo "<p><b>perl interpreters found using $METHOD:</b><ul>"

    for i in $REALPERL; do
        if [ -f "$i" -a -x "$i" ]; then
            p=`$i -e 'print "$]<br>Library paths:<br>
<font size=\"-1\"><tt>" . join("<br>", @INC) . "</font></tt>"'`
            echo "<li><b><tt>$i</tt></b><br>Version: $p</li>"
        fi
    done

    echo "</ul></p>"
fi

echo '<hr size="1" width="100%">
<font size="-1">findPerl 0.1 beta - Copyright &#0169; 2001 Christian R
+enz -
<a href="http://www.web42.com/software/findperl/">findPerl Homepage</a
+></font>
</blockquote>'

### eof ###

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://186772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found