vim search for ) replace with text then newline then )

Problem

I have a huge sql query with 574 lines and I needed to replace a closing bracket ) with text and then a new line with a closing bracket

Before:


) AS

After:


GROUP BY v.visit_id
) AS

Solution

Using vim’s search and replace feature


:%s/^)/GROUP BY v.visit_id\r)/gc

The above searches for the lines beginning with the closing bracket ) and then replaces it with text and then new line (\r) followed by a closing bracket )

References

How to replace a character by a newline in Vim

Add a newline after given patterns

Enable Windows Defender on Windows 7

Problem

Windows defender was not running and needed to activate it.

Solution

There is this nice youtube video explaining this process. Below is a summary:

  • Open Control Panel
  • Then Go to View by Categories and select Large icons:

Selection_999(1261).png

  • Then you should see windows defender at the bottom of the page:

Selection_999(1262).png

  • Once you click on it, it will ask you if you want to start it, click ok and you are good to go.

This program is blocked by group policy

Problem

I got this error when trying to enable windows defender from the control panel.

This program is blocked by group policy error message
This program is blocked by group policy

On doing some research it appears this may have been caused by a malware and a virus scan upon activating windows defender validated this suspicion.

Solution

The solution as shown in this youtube video was to delete policies from the registry. I did not use the batch file. Deleting the registry entries worked.

  • Reboot the machine and then press F8 as it is booting to go into safe mode.
  • Once its started from the start menu type Regedit to open the windows registry.
  • Then First create a backup of the registry by clicking File Followed by Export and save to a location of your choice.
  • Then Next delete the following registry entries. You can review this video in-case the screenshots below are not clear.
First regristry key to be deleted
First registry key to be deleted
Second regristry key to be deleted
Second registry key to be deleted
Third regristry key to be deleted
Third registry key to be deleted
Last registry key to be deleted
Last registry key to be deleted

References

How To Fix This Program is Blocked by Group Policy in Windows 7/8/10

Installing virtualbox plus GUI ubuntu 16.04

Problem

Had virtual box installed and was using it from the command line. The process of creating a new virtual machine using this approach proved difficult. Tools like vagrant make this process easier but I needed to share this image with a non vagrant user.

Solution

Installed the default version of virtualbox that comes with ubuntu 16.04.

When I tried installing the latest version of virtual box, I would get the following error when starting a newly defined image:


Failed to open a session for the virtual machine bandago.

The virtual machine 'vmImage' has terminated unexpectedly during startup with exit code 1 (0x1).

Result Code: NS_ERROR_FAILURE (0x80004005)
Component: MachineWrap
Interface: IMachine {85cd948e-a71f-4289-281e-0ca7ad48cd89}

The solution maybe to after installing virtualbox, additionally installing the following packages:

(I never got to test this though)

vde2

virtualbox-guest-additions-iso

virtualbox-qt

Solution

Install virtualbox and the above packages:


imela@whiscardz ~ $ sudo apt-get install virtualbox virtualbox-guest-additions-iso virtualbox-qt
Reading package lists... Done
Building dependency tree
Reading state information... Done
virtualbox is already the newest version (5.1.38-dfsg-0ubuntu1.16.04.2).
The following NEW packages will be installed:
virtualbox-guest-additions-iso virtualbox-qt
0 upgraded, 2 newly installed, 0 to remove and 2 not upgraded.
Need to get 47.4 MB of archives.
After this operation, 87.4 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Note: After defining a new vm, when it’s time to link the ISO, double click on the vm definition and then select the iso.

References

Creating a Virtual Machine

Installing Oracle VM VirtualBox and Extension Packs

Oracle Linux_Downloads

How to Install VirtualBox 5.2 on Ubuntu 16.04 LTS

Exporting and Importing Virtual Box Images

Problem

Needed to save a virtual box image to be shared with someone else

Solution

Using vboxmanage command line to export the image and then test importing the image.

Steps

  • First list the virtual box images available

imela@whiscardz$ vboxmanage list vms
"test_default_1549514247520_18667" {6e29d56a-6531-4274-9d91-c6719e9fdaf3}
  • Then export the image you want to a file

imela@whiscardz$ vboxmanage export test_default_1549514247520_18667 -o test_default_1549514247520_18667.ova

  • Then copy it to the machine that you want to import the image.
  • Finally import the image.

imela@whiscardz2$ vboxmanage import test_default_1549514247520_18667.ova
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Potential Issues

When I tried exporting to a file name other than the name of the image, it failed and threw the error below (it could be the extention):


imela@whiscardz2$ vboxmanage export test_default_1549514247520_18667 --output otherFileName.ovf
0%...
Progress state: VBOX_E_IPRT_ERROR
VBoxManage: error: Appliance write failed
VBoxManage: error: RTVfsFsStrmAdd failed for 'otherFileName.ovf' (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code VBOX_E_IPRT_ERROR (0x80bb0005), component ApplianceWrap, interface IAppliance
VBoxManage: error: Context: "RTEXITCODE handleExportAppliance(HandlerArg*)" at line 1263 of file VBoxManageAppliance.cpp

References

How to export and import VirtualBox VM images?

VBoxManage registervm/unregistervm

Export to OVF

VBoxManage export

VBoxManage import

timedatectl

Problem

An ubuntu server 16.04 time was not being synchronized. Here was the error in the syslog:


timesyncd[26781]: Timed out waiting for reply from [2001:67c:1560:8003::c8]:123 (ntp.ubuntu.com)

 

When I checked time timedatectl NTP synchronized was showing as off and when I tried to turn it on it wasn’t changing state.


# timedatectl
Local time: Mon 2019-01-21 10:49:54 XXX
Universal time: Mon 2019-01-21 07:49:54 UTC
RTC time: Mon 2019-01-21 07:53:45
Time zone: One/Two (XXX, +0300)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no

# timedatectl set-ntp on
# timedatectl
Local time: Mon 2019-01-21 10:54:41 XXX
Universal time: Mon 2019-01-21 07:54:41 UTC
RTC time: Mon 2019-01-21 07:58:32
Time zone: One/Two (XXX, +0300)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no
# timedatectl
Local time: Mon 2019-01-21 11:12:14 XXX
Universal time: Mon 2019-01-21 08:12:14 UTC
RTC time: Mon 2019-01-21 08:16:05
Time zone: One/Two (XXX, +0300)
Network time on: yes
NTP synchronized: no
RTC in local TZ: no

Solution

I needed to update the firewall settings and allow outgoing traffic for the ntp port. After this the time was synchronized:


systemd[1185]: Time has been changed

Then when you check timedatectl


# timedatectl
Local time: Mon 2019-01-21 11:35:04 XXX
Universal time: Mon 2019-01-21 08:35:04 UTC
RTC time: Mon 2019-01-21 08:35:04
Time zone: One/Two (XXX, +0300)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no

References

How To Set Up Time Synchronization on Ubuntu 16.04

How to use ntpdate behind a proxy?

I18n support in mod_proxy_html requires mod_xml2enc

Problem

I was configuring reverse proxying for apache and was getting the following error:


AH01425: I18n support in mod_proxy_html requires mod_xml2enc. Without it non-ASCII characters in proxied pages are likely to display incorrectly

Solution

Needed to enable the xml2enc module:


root@server:~# a2enmod xml2enc
Enabling module xml2enc.
To activate the new configuration, you need to run:
service apache2 restart
root@server:~# service apache2 stop
* Stopping web server apache2
*
root@server:~# service apache2 start
* Starting web server apache2
*

References

i18n-support-in-mod_proxy_html-requires-mod_xml2enc-without-it-non-ascii-characters-in-proxied-pages-are-likely-to-display-incorrectly

18n-support-in-mod_proxy_html-requires-mod_xml2enc-without-it-non-ascii-characters-in-proxied-pages-are-likely-to-display-incorrectly

apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1

Problem

Was getting the following warning on a new instance of apache on ubuntu 14.04


AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

Solution

From this reference, you can resolve this by doing the following:

Update 2019-02-14


root@server:~$ sudo a2enconf fqdn
ERROR: Conf fqdn does not exist!

root@server:~$ echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf
ServerName localhost


root@server:~# sudo a2enconf fqdn
Enabling conf fqdn.
To activate the new configuration, you need to run:
service apache2 reload
root@server:~# service apache2 reload
* Reloading web server apache2

References

apache-error-could-not-reliably-determine-the-servers-fully-qualified-domain

Removing symbolic link vmlinuz.old you may need to re-run your boot loader[grub]

Problem

Did an apt-get autoremove on ubuntu 14.04 to clean up old kernel images.

Got the following warning


The link /vmlinuz.old is a damaged link
Removing symbolic link vmlinuz.old
you may need to re-run your boot loader[grub]
The link /initrd.img.old is a damaged link
Removing symbolic link initrd.img.old
you may need to re-run your boot loader[grub]

Solution

From this explanation, you don’t really need to do anything to resolve the above.

For sanity, you can still run update-grub as explained here:


$ sudo update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.13.0-160-generic
Found initrd image: /boot/initrd.img-3.13.0-160-generic
Adding boot menu entry for EFI firmware configuration
done

References

how-do-i-re-run-boot-loader

you-may-need-to-re-run-your-boot-loader-grub