{"id":1188,"date":"2015-01-02T10:04:59","date_gmt":"2015-01-02T09:04:59","guid":{"rendered":"https:\/\/www.hutsky.cz\/blog\/?p=1188"},"modified":"2016-03-03T22:57:04","modified_gmt":"2016-03-03T21:57:04","slug":"check-the-wordpress-version-of-several-sites-at-once","status":"publish","type":"post","link":"https:\/\/www.hutsky.cz\/blog\/2015\/01\/check-the-wordpress-version-of-several-sites-at-once\/","title":{"rendered":"Check the WordPress version of several sites at once"},"content":{"rendered":"<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-1198\" src=\"https:\/\/www.hutsky.cz\/blog\/wp-content\/uploads\/wordpress-logo-32.png\" alt=\"wordpress-logo-32\" width=\"32\" height=\"32\" \/>I&#8217;ve got this blog of mine where I log in every now and then, so whenever there is a new version of WordPress, I see the update reminder message. There is, however, over a dozen other blogs under my wings and I don&#8217;t log into those nearly as often, in fact, I hardly log into them at all. Some more savvy admins of those blogs take care of the updates themselves, some don&#8217;t. Leaving those blogs not updated poses a significant risk, so I thought I would create a tool that would keep me informed.<\/p>\n<p style=\"text-align: justify;\">It&#8217;s also possible to acivate the Automatic Background Updates, but with a few custom-made plugins in place, I prefer some degree of human supervision over the update process, either testing the update on a development machine first, or at least to be able to see if something goes wrong immediately.<\/p>\n<p style=\"text-align: justify;\">So I wrote this perl script that will keep an eye on those websites for me. The only problem is that it depends on meta tag &#8220;generator&#8221; to get the WordPress site&#8217;s version, and some themes prefer to keep this information hidden.<\/p>\n<p style=\"text-align: justify;\">Uning Cron, this script will email the results to your address at some convenient time, once a week sounds just about right for me.<\/p>\n<p style=\"text-align: justify;\">You only need to add more URLs into the array on line 41:<\/p>\n<pre>#!\/usr\/bin\/perl\r\n#\r\n#       .--' |\r\n#      \/___^ |     .--.\r\n#          ) |    \/    \\\r\n#         \/  |  \/`      '.\r\n#        |   '-'    \/     \\\r\n#        \\         |      |\\\r\n#         \\    \/   \\      \/\\|\r\n#          \\  \/'----`\\   \/\r\n#          |||       \\\\ |\r\n#          ((|        ((|\r\n#          |||        |||\r\n#  perl   \/\/_(       \/\/_(   script :)\r\n\r\nuse strict;\r\nuse Data::Dumper;\r\nuse LWP::UserAgent;\r\nuse Email::MIME;\r\n\r\nmy $wp_url = 'https:\/\/wordpress.org\/latest.tar.gz';\r\nmy $message = '';\r\n\r\n# get information from $wp_url using HEAD method\r\nmy $ua = LWP::UserAgent-&gt;new;\r\n$ua-&gt;timeout(10);\r\n$ua-&gt;env_proxy;\r\nmy $response = $ua-&gt;head($wp_url);\r\n\r\n\r\nif ($response-&gt;is_success) {\r\n\tif ($response-&gt;header('content-disposition') =~ m\/wordpress-([0-9\\.]+)\\.tar\\.gz\/) {\r\n\t\tmy $wp_version = $1;\r\n\t\tmy $wp_site_content;\r\n\t\tmy $wp_update_url;\r\n\t\tmy $wp_site_version;\r\n\t\t\r\n\t\tforeach my $url (\r\n\t\t\t'http:\/\/www.example.com\/blog\/',\r\n\t\t\t'http:\/\/www.example2.com\/',\r\n\t\t\t# 'add more here',\r\n\t\t) {\r\n\t\t\t#print \"\\n$url\\n\";\r\n\t\t\tmy $wp_site = LWP::UserAgent-&gt;new;\r\n\t\t\t$wp_site-&gt;timeout(10);\r\n\t\t\t$wp_site-&gt;env_proxy;\r\n\t\t\t$wp_site_content = $wp_site-&gt;get($url);\r\n\t\t\tif ($wp_site_content-&gt;is_success) {\r\n\t\t\t\tif ($wp_site_content-&gt;decoded_content =~ m\/&lt;meta\\s+name=\"generator\"\\s+content=\"WordPress\\s+([0-9\\.]+)\"\/) { $wp_site_version = $1; if ($wp_site_version ne $wp_version) { $wp_update_url = $url; $wp_update_url =~ s\/\\\/$\/\/; #remove the trailing \/ $message .= \"- $url is version $wp_site_version (update here: $wp_update_url\/wp-admin\/update-core.php ) \\n\"; } else { $message .= \"- $url is up-to-date\\n\"; } } else { $message .= \"- unable to determine WP version of $url - hidden generator tag?\\n\"; } } else { $message .= \"- unable to determine read $url\\n\"; } undef $wp_site; undef $wp_site_content; undef $wp_site_version; sleep 1; } if ($message ne '') { $message = \"The following sites have been checked against the current stable version of WordPress: \\n\\n\\n\" . $message; my $email_message = Email::MIME-&gt;create(\r\n\t\t\t  header_str =&gt; [\r\n\t\t\t    From    =&gt; 'from@example.com',\r\n\t\t\t    To      =&gt; 'to@example.com',\r\n\t\t\t    Subject =&gt; 'Wordpress sites report',\r\n\t\t\t  ],\r\n\t\t\t  attributes =&gt; {\r\n\t\t\t    encoding =&gt; 'quoted-printable',\r\n\t\t\t    charset  =&gt; 'ISO-8859-1',\r\n\t\t\t  },\r\n\t\t\t  body_str =&gt; $message,\r\n\t\t\t); \r\n\t\t\tuse Email::Sender::Simple qw(sendmail);\r\n\t\t\tsendmail($email_message);\r\n\t\t}\r\n\t}\r\n\telse {\r\n\t\tdie 'Unable to determine current stable WordPress version';\r\n\t}\r\n\t\r\n}\r\nelse {\r\n    die $response-&gt;status_line;\r\n}\r\n<\/pre>\n<p>And this is what the incoming email looks like (supposing there are a couple of URLs):<\/p>\n<p>Subject: WordPress sites report<\/p>\n<p>&#8211; http:\/\/www.example.com\/blog\/ is up-to-date<br \/>\n&#8211; http:\/\/www.example2.com\/ is version 3.9.2 (update here: http:\/\/www.example2.com\/wp-admin\/update-core.php )<br \/>\n&#8211; http:\/\/www.example3.com\/ is version 4.0 (update here: http:\/\/www.example3.com\/wp-admin\/update-core.php )<br \/>\n&#8211; http:\/\/www.example4.com\/ is up-to-date<br \/>\n&#8211; unable to determine WP version of http:\/\/www.example5.com\/ &#8211; hidden generator tag?<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve got this blog of mine where I log in every now and then, so whenever there is a new version of WordPress, I see the update reminder message. There is, however, over a dozen other blogs under my wings &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.hutsky.cz\/blog\/2015\/01\/check-the-wordpress-version-of-several-sites-at-once\/\"> <span class=\"screen-reader-text\">Check the WordPress version of several sites at once<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,22],"tags":[45,42,44],"class_list":["post-1188","post","type-post","status-publish","format-standard","hentry","category-programming","category-web-related","tag-perl","tag-web","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/posts\/1188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/comments?post=1188"}],"version-history":[{"count":21,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/posts\/1188\/revisions"}],"predecessor-version":[{"id":1399,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/posts\/1188\/revisions\/1399"}],"wp:attachment":[{"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/media?parent=1188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/categories?post=1188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hutsky.cz\/blog\/wp-json\/wp\/v2\/tags?post=1188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}