Ubuntu 22.04 Find Files

Find a file

find ./ -name "file_to_find.txt"  2>&1 | grep -v "Permission denied"

Find In Files (File containing text), recursively from current folder

grep -r "text_to_search_for" .
Rubbish Service Rant

A Nightmare called Afrihost

And now for something completely different…..

I just want to fill you in on what a rip off Afrihost is, and how they are either the most incompetant service provider on the planet, or as corrupt and crooked a company as you can get. Or perhaps everyone at Afrihost is simply dumb as nails…. who knows.

As I have been using one of their cheaper hosting options for over eight years now, I decided to go with them when installing a new fibre connection to the new house my wife and I just purchased. Over those 8 years downtime has probably been a little more that I would have liked, but at least is was a decent price.

With the new house comes additional responsibility, so stepping up the game comes part and parcel with that. New PC, fast internet, and server upgrade. It seemed easy…… but alas, enter Afrihost.

I ordered a 500/500 fibre line. Below is a timeline of what followed.

The TL;DR of it is do not use these clowns at Afrihost, they are complete idiots.

Wed 8 Feb 2023Placed order for 500Mbps/500Mbps Firbre connection
Sat 11 Feb 2023Received confirmation From Afrihost that they received the order
Wed 15 Feb 2023After being advised of pending installation, went to the new house and cable installation was done. I was advised line would be activated within 24 hours
Fri 17 Feb 2023Went back to house with router to test installation. Connected ok, but speed at showed it to be well below 50Mbps. Was advised by support operator that the problem was with my phone, and she could see 500Mbps up and down. I was told to bring a laptop to test the speed. On activation I was immediately billed for a 500/500 connection (pro-rata for the month)
Sun 19 Feb 2023Moved into house. Set up PC, and did a speed test. Speed showed no more that 50 Mpbs up and down. I detailed the problem to afrihost with screenshots.
Monday 20 Feb 2023Received response from Afrihost, with repeated requests during the day for me to clear cache, only use ethernet cable, etc. I was eventually advised that Afrihost had opened a ticket with Metro to investigate, and no further communications were recived for the day.
Tue 21 Feb 2023I requested an update. None was received
Wed 22 Feb 2023I requested and update again, twice during the day, and got another request (very late afternoon) to clear cache, use LAN cable, etc to test the speed. I duly supplied all screenshots, but go no response thereafter.
Thu 23 Feb 2023I received an Invoice for a 500/500 connection, which it was not. I emailed Afrihost asking it that was a joke. I finally received a reply from Afrihost at 16h41 asking me what the problem was. I responded detailing the problem, and that if the problem was not resolved during the day I would cancel the order. No reply was received, and no update.
Fri 24 Feb 2023I notified Afrihost of the cancellation of the order as no further update had been received. Suddenly there was a slight change, and the connection became 50Mbps/500Mbps. I also received an email from Afrihost notifying me that they will pass a credit for the difference between the 500 and the 50 package, with no reason given for not being able to sort the issue out, and no intent shown on sorting the issue out. I responded that he had misread my email, and that the cancellation stands.
Mon 27 Feb 2023I received another notification that the cancellation will only take effect at the end of March. I objected strongly as I have to this date not received what I ordered and PAID FOR. Afrihost deducted their thumb suck fee off of my bank account.
Wed 1 Mar 2023I was notified by Afrihost that on top of being billed for March for something I did not order, they would be billing me for the router as I had canceled within 6 months. Once again I objected strongly with no response from Afrihost.
Thu 2 Mar 2023The line was disconnected, this 2 days after Afrihost took a payment for it for the month of March. My email response was again ignored. No communications were received from Afrihost regarding the disconnection.

And another day passes…. no updates, no fibre connection, and no confirmation of it being disconnected. Which would imply Afrihost deducted the money from my bank account with criminal intent.

As I said in the beginning, step very wide of these clowns.

Sun 5 Mar 2023For whatever reason the connection is restored. Safe to presume then it was a breakdown????? who knows with afrihost. Not the connection I ordered btw, just the order that afrihost decided to give me instead, and steal my money for.
Thu 16 Mar 2023Received an email from Afrihost, asking if my connection has been sorted out. I replied not even close, with a link to this blog post rather than have to repeat myself yet again. No reply and no further contact from Afrihost.
Thu 18 Mar 2023Received an email from Afrihost, asking me to perform more tests. not bothering, nor bothering to reply. New supplier has already been sourced, so now just biding my time till this rubbish ends at month end.
Sun 09 Apr 2023Afrihost criminally deducted R999 from my account due to me ‘cancelling the contract’ within 12 months. At zero point did Afrihost supply the contract that was deducted for. The contract was never cancelled, I simply cancelled the order for failure to deliver. At least I have seen the last of that completely rubbish and criminal company. Good riddance.
jQuery wordpress

Using AJAX in WordPress

In the constructor of your PHP class add the following


In your enqueue function add the localize script function so you have a variable to use in the js file to call admin-ajax.php

		wp_enqueue_script('traffic-report', '/js/myjsfile.js', array('jquery'), '3.0');
		wp_localize_script('traffic-report', 'script_vars',array( 'AJAXurl' => admin_url( 'admin-ajax.php' ) ) );

Then add the callback functions to the same class

function send_email_test()
	//here do whatever you need to do with the data posted from the ajax call
	echo "ok";//anything that gets echo'd will resturn as the result in the javascript ajax function

Then in your js file add the following, assuming you have an element with an ID of #send_mail_test which you click on to call the AJAX request.

			url: script_vars.AJAXurl,
			method: "POST",
			data: {
				'action': 'send_email_test',//PHP function name to call
				'device': iDevice //Data to send to ajax function
			success: function (result)
				if (result)
					console.log("result is empty");
php wordpress

Creating a WordPress Class with Backend and Frontend functionality

Firstly, a bare bones PHP class. Add this in it’s own file, eg mynewclass.php, and include it in functions.php

class MyNewClassName
	public function __construct()

$mynewclass=new MyNewClassName();

Now a slightly more sophisticated one to add an admin menu item and page, with page tabs.

class MyNewClassName
	protected $admin_page_url;
	public function __construct()
	function my_new_class_admin_menu()
		add_menu_page("My New Class","My New Class","manage_options",$this->admin_page_url,array($this,"my_new_class_page_contents"),"dashicons-schedule",3);
	function my_new_class_page_contents()
		$default_tab = 'general';
		$tab = isset($_GET['tab']) ? $_GET['tab'] : $default_tab;
		echo "<div class='wrap'>";
		echo "<h1>".esc_html( get_admin_page_title())."</h1>";
		echo '<nav class="nav-tab-wrapper">';
			<a href="?page=<?php echo $this->admin_page_url;?>&tab=general" class="nav-tab <?php if($tab==='general'):?>nav-tab-active<?php endif; ?>">General</a>
   		echo '</nav>';
   		echo '<div class="tab-content">';
   		switch($tab) :
   			case 'general':
   				echo $this->general_tab();

   		echo '</div>';
	function general_tab()
		echo "<div>";
		echo "<p>hello world!</p>";
		echo "</div>";
$mynewclass=new MyNewClassName();

Ubuntu 22.04 Fix Broken Pipe on apt-get

apt-get -o DPkg::Options::="--force-overwrite" install <package name>

This will force an overwrite.
Linux localhost Node

Ubuntu 20.04 Node Server on localhost with SSL

To get SSL on your localhost for testing purposes you will need a SSL key and certificate generated. I do the following in a certs directory to call up later in the node server app.

openssl genrsa -des3 -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem

Import the rootCA.pem file into your browser under the ‘Authority‘ tab.

Then create server.cnf as follows

default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn

CN = localhost

… and v3.ext as follows

keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

DNS.1 = localhost

Using the above config files you can create the server key and certificate with the following

openssl req -new -sha256 -nodes -out server.csr -newkey rsa:2048 -keyout server.key -config <( cat server.csr.cnf )

openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days 500 -sha256 -extfile v3.ext

Now you can start the server with npm start or node server.js, with server.js as follows (basic example)

const express = require('express')
const app = express()
const https = require('https')
const fs = require('fs')
const port = 3000

app.get('/', (req, res) => {

const httpsOptions = {
  key: fs.readFileSync('./certs/server.key'),
  cert: fs.readFileSync('./certs/server.csr')
const server = https.createServer(httpsOptions, app).listen(port, () => {
  console.log('server running at ' + port)

Open your browser and go to https://localhost:3000 and all should be good.

Linux Node npm

Installing Node on Ubuntu 20.04

Step 1 Do the usual first, i.e.

sudo apt update


sudo apt upgrade

Step 2 Make sure npm is up to date as well

npm cache clean -f
npm install -g n #if not already installed
sudo n stable

It might take some doing to achieve the above, as I had a few issues to deal with ion Ubuntu 20..04 Firstly I had to update npm and node :

curl -fsSL | sudo -E bash -
sudo apt-get install -y nodejs

Then I had to change the permissions on the node modules directory

sudo chown -R $USER /usr/local/lib/node_modules

Only then could I get sudo npm install -g to work as intended.

MySql wordpress

SQL to extract order report

SELECT pm.meta_value AS city,p.ID as order_id,p.post_excerpt as
customer_note,p.post_date as order_date,pm2.meta_value as
suburb,pm3.meta_value as customer_id,
pm4.meta_value as sender_email,
pm5.meta_value as sender_firstname,
pm6.meta_value as sender_lastname
FROM wp_posts p
LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id
LEFT JOIN wp_postmeta pm2 ON p.ID = pm2.post_id
LEFT JOIN wp_postmeta pm3 ON p.ID = pm3.post_id
LEFT JOIN wp_postmeta pm4 ON p.ID = pm4.post_id
LEFT JOIN wp_postmeta pm5 ON p.ID = pm5.post_id
LEFT JOIN wp_postmeta pm6 ON p.ID = pm6.post_id
WHERE p.post_type='shop_order'
AND p.post_status='wc-completed'
AND pm.meta_key='_shipping_address_2' AND pm.meta_value='Durban'
AND pm2.meta_key='_shipping_city'
AND pm3.meta_key='_customer_user'
AND pm4.meta_key='_billing_email'
AND pm5.meta_key='_billing_first_name'
AND pm6.meta_key='_billing_last_name'
ORDER BY p.post_date DESC

This SQL string will extract multiple meta values from an order.


Ubuntu 18.04 Disable Auto Time Updates

Firstly disable automatic times

timedatectl set-ntp off

Then simple set the time manualy, or the time itself will still automatically update.

sudo date --set "21 Dec 2020 14:42:00"

To re-enable automatic date/time updates use

timedatectl set-ntp on

To check the status use

timedatectl status

You should see something like below. the three ‘no’ mean it’s disabled.

Local time: Mon 2020-12-21 15:00:02 SAST
Universal time: Mon 2020-12-21 13:00:02 UTC
RTC time: Mon 2020-12-21 12:56:50
Time zone: Africa/Johannesburg (SAST, +0200)
System clock synchronized: no
systemd-timesyncd.service active: no
RTC in local TZ: no

Cleaning Ubuntu boot partition

Often the Ubuntu upgrades will fail fue to a no space error. The only solution is to remove old kernels manually.

The first step is to show which kernel you are currently running, as you do not want to delete this one.

sudo su
uname -r

So change to the boot directory for simplicity and list all existing kernels on the system.

cd /boot
ls -al

Then you can remove the older kernels…

apt remove linux-image-4.15.0-99-genericapt remove linux-image-4.15.0-99-generic

… and clean up.

apt --purge autoremove

You can retry the upgrade

apt full upgrade