Friday, 12 January 2024

How to print out log entries that have more than two lines?

to print out the entries in server.log:

 gawk -v RS= '(gsub(/\n/, "&") > 2) { print; printf "\n" }' server.log

 

to print out the entries in all files (oldest first, newest last):

ls -tr | while read p; do cat $p; done | gawk -v RS= '(gsub(/\n/, "&") > 2) { print; printf "\n" }'

Friday, 31 March 2023

How to convert PDF file to TXT file on CentOS 7 ?

yum install poppler-utils

pdftotext -layout test.pdf - | awk '!NF{print "\n"}END{print "\n"}1' ORS=" " | tr -s ' ' > test.txt

Thursday, 3 November 2022

How to generate a random password quickly in BASH?

To generate a 32-chars random password with letters and digits:

openssl rand -base64 128 | tr -dc [:alnum:] | cut -c -32

Monday, 14 February 2022

How to share a folder with your minimal CentOS guest in VirtualBox?

 

  1. yum install bzip2 kernel-devel gcc make perl
  2. click 'insert Guest Additions CD Image ...' from VirtualBox Manager's Devices menu;
  3. mount /dev/cdrom /mnt
  4. cd /mnt
  5. ./VBoxLinuxAdditions.run
  6. reboot
  7. add a shared folder, say 'temp', to the guest from VirtualBox Manager's Devices menu;
  8. mount -t vboxsf temp /mnt

Wednesday, 3 April 2019

winword is freezing after pasting from followed by closing powerpoint on Windows 10

With 'Analyse wait chain' from task manager, you can see that winword is still waiting for powerpoint. Even the powerpoint has been closed (by clicking the x on top right of its window), there is still a powerpoint process running (not seen in 'processes' list, but in 'details' list). This looks like a 'bug' of powerpoint 2016. If you close powerpoint file by Ctrl+F4, then close the powerpoint app, everything is fine. If you close powerpoint app by Alt+F4, you have the same problem.

Saturday, 16 February 2019

How to make a disk dump using dd command?

To virtualize a physical PC in VirtualBox (see here), I need a copy of its disk image. The PC is quite old 386 (32bit) and its spec is quite low. So, I choose the less resource demanding Linux distro, Tiny Core (CorePlus version) to boot it up. To hold the big image file, I have a USB external drive in NTFS format. Here is what I did:

1. boot the PC with CorePlus

2. install ntfs-3g extension

3. connect the USB drive to the PC

4. find the device ID of the USB drive (in my case, sdd) with: fdisk -l

5. sudo -s

6. mount /mnt/sdd1

7. cd /mnt/sdd1/

8. dd if=/dev/sda of=sda_image.dd


Sunday, 19 August 2018

How to install RTL8811AU WiFi adapter?

Ubuntu
---------------------------------------------------------------------------------------------------------------------------
# Download Ubuntu desktop 18.04 ISO from here

# write the ISO image to a USB stick using w32 disk imager

# install minimal installation on a laptop using the USB stick

# boot the laptop by holding shift key after BIOS loading screen to get into GRUB)
select option:
Advanced options for Ubuntu
Ubuntu, with Linux 4.15.0-29-generic (recovery mode)
root (Drop to root shell prompt)
:~# mount -o rw,remount /
:~# vi /etc/gdm3/custom.conf
uncomment following line
#WaylandEnable=false in /etc/gdm3/custom.comf
^D

# resume the reboot

sudo apt-get update
sudo apt install dkms
sudo apt install git

# following instruction here to build the driver from source
git clone https://github.com/gnab/rtl8812au.git
sudo cp -r rtl8812au  /usr/src/rtl8812au-4.2.2
sudo dkms add -m rtl8812au -v 4.2.2
sudo dkms build -m rtl8812au -v 4.2.2
sudo dkms install -m rtl8812au -v 4.2.2
reboot

Update on 11/02/2019
---------------------------------------------------------------------------------------------------------------------------
I have tried following from here on lubuntu and Mint, Both work well:

sudo apt install git dkms build-essential
git clone https://github.com/abperiasamy/rtl8812AU_8821AU_linux.git
cd rtl8812AU_8821AU_linux
sudo make -f Makefile.dkms install

Note: you may need install the headers first
apt-get install linux-headers-$(uname -r)

Update on 13/02/2019
---------------------------------------------------------------------------------------------------------------------------
Another try on my old Dimension8400 with Debian9, and it seems working as well. Occasionally, the connection is dropped.
BTW, the out-of-box Debian9 has problem with my wifi and it dropped the connection immediately after authenticated with error: DEAUTH_LEAVING
The fix is simple as described here