Handy script: LAMP stack version printer

Often when troubleshooting or setting up servers, I need to know the installed versions of applications commonly grouped into the “LAMP” stack. I dislike having to remember the slight differences between them when trying to coerce each to divulge their version. So I created a script that does that, and even prints it all in easy-to-read colors!

The code [UPDATE, 2011-06-04: I've amplified the script below so it now prints more commonly useful applications. Let's call it LAMPPPR ;-) ]:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
###################################
#
# Written by Samuel Huckins
#
# July 2007
#
# Prints out version info for
# things in the LAMP stack.
#
###################################
#
echo -e "\e[1;34mThis machine's LAMP stack:\e[0m"
echo ""
# Linux:
LINUX=`cat /etc/issue`
echo -e -n " * \e[31mL\e[1;33minux: \e[0m"
echo "$LINUX"
# Apache:
echo -e -n " * \e[31mA\e[1;33mpache: \e[0m"
if [ -e /usr/sbin/httpd ]
then
echo "`/usr/sbin/httpd -v| head -n 1 | awk '{print $3}'`"
elif [ -e /usr/sbin/apache2 ]
then
echo "`/usr/sbin/apache2 -v| head -n 1 | awk '{print $3}'`"
else
echo -e "\e[37mNot present\e[0m"
fi
# MySQL:
echo -e -n " * \e[31mM\e[1;33mySQL: \e[0m"
if [ -e /usr/bin/mysql ]
then
echo "`/usr/bin/mysql --version | awk '/Ver/ {print $2, $3, $4, $5}' | sed 's/,//'`"
else
echo -e "\e[37mNot present\e[0m"
fi
# PHP:
echo -e -n " * \e[31mP\e[1;33mHP: \e[0m"
if [ -e /usr/bin/php ]
then
echo "`php -v`"
else
echo -e "\e[37mNot present\e[0m"
fi
# Perl:
echo -e -n " * \e[31mP\e[1;33merl: \e[0m"
if [ -e /usr/bin/perl ]
then
echo "`perl -v | awk '/This is perl/ {print $4}' | sed 's/v//'`"
else
echo -e "\e[37mNot present\e[0m"
fi
# Python:
echo -e -n " * \e[31mP\e[1;33mython: \e[0m"
if [ -e /usr/bin/python ]
then
echo "`/usr/bin/env python -V 2>&1 | awk '/Python/ {print $2}'`"
else
echo -e "\e[37mNot present\e[0m"
fi
# Ruby:
echo -e -n " * \e[31mR\e[1;33muby: \e[0m"
if [ -e /usr/bin/ruby ]
then
echo "`ruby --version | cut -f 2 -d' '`"
else
echo -e "\e[37mNot present\e[0m"
fi
# done
echo ""

The result:

Here’s the quickest way to get rolling. Update the second line, then paste it into a terminal:

1
2
3
4
5
6
7
8
9
# Update this variable as appropriate:
MYDIR="~/YOUR_FAVORITE_SCRIPTS_DIR"
cd $MYDIR
wget https://github.com/shuckins/sph_code/raw/master/sysadmin/misc/lamp-info-printer.sh
chmod u+x lamp-version-printer.sh
echo -e "# Prints version info of common applications:\n \
alias lamp='$MYDIR/lamp-version-printer.sh'"
>> ~/.bashrc
source ~/.bashrc
lamp

Couldn’t get much easier.

Minor caveat: While the script does check each program for existence, I only check the most common place. It could be better expanded to cover less used locations for applications, conventions on more OSes, etc. Consider the baton passed :-)

Post to Twitter Post to Delicious Post to Digg Post to Reddit

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

This entry was posted in CLI, Linux and tagged , , , , , . Bookmark the permalink.

One Response to Handy script: LAMP stack version printer

  1. Anonymous says:

    Neato! Works as advertised.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>