Nk_php_version

Home

Description

The nk_php_version() function is a Bash function that expects to be passed a domain name as its argument. It checks if the domain name is provided; otherwise, it prints an error message and returns.

The function then uses grep and awk commands to search for the domain name in the /etc/userdatadomains file and extract the PHP version associated with the domain.

The grep command searches for lines that start with the domain name followed by a colon : This helps prevent matching subdomains. The -E option enables extended regular expressions, and the ^ denotes the start of the line.

The awk command uses == as a delimiter to separate the fields in /etc/userdatadomains. The PHP version is the last field in the line, so $NF is used to print it.

Overall, the function returns the PHP version associated with the domain name passed as its argument.

Example:

[root@cloudvpsserver ~]# nk_php_version domain.com
ea-php81

Code

nk_php_version () {
# nk_php_version expects to be passed a domain name. Fail if not.
domain="$1"
if [ "$1" = "" ]; then
    echo "You must provide a domain name"
    return 0
fi
# No longer using whodat for performance reasons
# whodat "$1" | awk '/PHP\ Version:/ {print $NF}'


# Using grep -E to find the domain in userdatadomains.
# Need the ^ to denote that it's the start of the line and the : to end off the search. This helps prevent matching subdomains.
# And the docroot is the last field in /etc/userdatadomains when using "==" as a delimeter.
grep -E "^$domain:" /etc/userdatadomains | awk -F "==" '{print $NF}'
}

Author: Nichole Kernreicht

Created: 2023-04-09 Sun 21:05