here's my trouble.
Let me describe the situation: I work on a large number of servers which contain a large number of customers; all of them have a webspace, but only some of them are using Wordpress.
For security reasons, I would like to get the Wordpress version of all the Wordpress installations of a specific server (I would apply the process to others after I found a solution).
I found the file /wp-includes/version.php which contains the line "$wp_version = 'x.x.x'" - seems perfect for keeping an eye on the installations of the customers and notify them when their version is dangerous.
I began to write of a command line I would then put into a cron to retrieve results, once a month:
for files in $(find /home -type f -iwholename "*/wp-includes/version.php") ; do domain=$(echo $files | awk -F'domains/' '{print $2}' | awk -F'/' '{print $1}') ; version=$(grep "wp_version = " $files | awk -F'=' '{print $2}') ; echo "$domain : $version" ; done | grep -v "4.8" | sed -e "s/'/ /g" -e "s/;/ /g"
The line above produces a result of this kind:
domain.com : 4.1.3
another.com : 4.7.6
again.com : 4.7.6
Looks like I got the result I wanted - but, as you can see, this command line is REALLY long and even if I tried different versions, I didn't find an elegant variant.
Of course, I tried different versions until this result, and this is the only one working correctly; and I haven't been able to find something similar, but better. The real problem is, I think, related to the variable definitions from a result; I am learning awk but it's something like ugly, even if it's an awesome tool. The sed command at the end clears the raw result that looks like this:
domain.com : '4.1.3';
another.com : '4.7.6';
again.com : '4.7.6';
The wp-includes/version.php looks similar to it:
<?php
/**
* The WordPress version string
*
* @global string $wp_version
*/
$wp_version = '3.9'; # for example
...
Could you please tell me if you see any "optimization"? This is more about education than real trouble.
Edit : the most optimized version for the moment is the following one in my opinion (clear enough for easy modifications, clean result, not so hard-to-understand functions):
for f in $(find /home -iwholename "*/wp-includes/version.php") ; do d=$(echo $f | awk -F'domains/' '{print $2}' | cut -d"/" -f1) ; v=$(grep '$wp_version = ' $f | sed -e 's/$wp_version = //g' -e "s/'//g" -e 's/;//g') ; echo "$v - $d" ; done