Identify php versions per domain per user in directadmin

At times you might want to get a list of which php versions are in use by which domain. There’s a plugin for directadmin for that (https://wavoe.bitbucket.io/phpversionlist/phpversionlist.tar.gz) but you can’t easily export the info to excel, especially when doing multiple servers. This script makes a nice csv.

Changelog:
v2.2: 2022/02/11: added creator

#!/bin/bash

##################################################################
# phpversions.sh v2.2                                            #
# Identifies which domain from which user uses which PHP version #
# and exports it to a csv file.                                  #
# Also works with CloudLinux servers and lsphp                   #
# (c)opyleft Take13                                              #
##################################################################
OPTIONSCONF=/usr/local/directadmin/custombuild/options.conf
USERS=/usr/local/directadmin/data/users
OUTFILE=`hostname`.csv
php1=`grep php1_release $OPTIONSCONF | awk -F = '{print $2}'`
php2=`grep php2_release $OPTIONSCONF | awk -F = '{print $2}'`
php3=`grep php3_release $OPTIONSCONF | awk -F = '{print $2}'`
php4=`grep php4_release $OPTIONSCONF | awk -F = '{print $2}'`

#echo "PHP1:" $php1
#echo "PHP2:" $php2
#echo "PHP3:" $php3
#echo "PHP4:" $php4

echo "User;Creator;Domain;PHP" > $OUTFILE

for USER in `ls -1 $USERS` ; do

	CREATOR=`grep creator /usr/local/directadmin/data/users/$USER/user.conf | awk -F = '{print $2}'`
	for DOMAIN in `cat $USERS/$USER/domains.list` ; do

		PHPSELECT=`grep php1_select $USERS/$USER/domains/$DOMAIN.conf | awk -F = '{print $2}'`

		case $PHPSELECT in

			1)
			PHPVER=$php
			;;
			2)
			PHPVER=$php2
			;;
			3)
			PHPVER=$php3
			;;
			4)
			PHPVER=$php4
			;;

			*)
			COUNT=`grep -c php=OFF $USERS/$USER/domains/$DOMAIN.conf`
			if [ "$COUNT" = "1" ] ; then
				PHPVER="PHP uitgeschakeld in domeinconfig"
			else
				PHPVER="Onbekende PHP instelling"
			fi
			;;

		esac

		echo $USER";"$CREATOR";"$DOMAIN";"$PHPVER >> $OUTFILE
		done
	done

If you have multiple servers and want to run it on those servers easily, just make sure you can connect to all servers (via ssh-key) and use this script:

#!/bin/bash

##################################################################
# Distributes phpversions.sh to configured servers, executes the #
# scripts and retrieves the csv file to current directory        #
##################################################################

for HOST in server1 server2 server3 server4 server5 etc ; do

	echo "Sending latest phpversions.sh to "$HOST
	scp phpversions.sh $HOST:
	echo "Gathering info"
	ssh $HOST 'chmod u+x phpversions.sh ; ./phpversions.sh'
	echo "Retrieving info"
	scp $HOST:*.csv .

done

Comments

Leave a Reply

Your email address will not be published.

4 + 4 =