Linux Tips & Tricks

Last updated: 17-Oct-2019

Most are tested on Ubuntu 18.04 and/or above.

Web / Networking

Samba Public Folder Sharing

Public folder sharing is useful for applications such as saving files from the scanner.

Install Samba.
$ sudo apt install samba

Create the public folder for sharing.
$ mkdir -p /PATH_TO_SHARED
$ chmod a+rw /PATH_TO_SHARED

Modify the configuration file.
$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.ORIG
$ sudo vi /etc/samba/smb.conf
...
(Append the following lines)
[Public]
path = /PATH_TO_SHARED
available = yes
browsable = yes
public = yes
writable = yes

Restart the Samba service.
$ sudo systemctl restart smbd

Setup Let's Encrypt

For Apache2 on Ubuntu:
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt install certbot python-certbot-apache
$ sudo certbot --apache

Setup MRTG

Here, on PC and Raspberry Pi.

Download All Links from a Web Page

$ wget --no-directories --accept='*.pdf' -r -l 1 URL

Disable WiFi on Ethernet Connection

Follow the instructions here. However, I need to change eth*) to enp*). Use ifconfig to find out the interface name.

Printing

CUPS Print Server

To expose and share printers added to a computer.
$ sudo cp /etc/cups/cupsd.conf /etc/cups/cupsd.conf.ORIG
$ sudo vi /etc/cups/cupsd.conf
(Modify)
Port 631             # Replaces: Listen localhost:631
Browsing On          # Replaces: Browsing Off
<Location />
  Order allow, deny
  Allow @LOCAL       # Add this line
</Location>
$ sudo systemctl restart cups

Notes:

  • Android: Check if your phone can discover and support the printing directly. It 'seems' that:
    • Prior to Android 8.0 Oreo: No built-in printing support; Can install CUPS Printing to support discovering CUPS Print Server.
    • Since Android 8.0 Oreo: With integrated printing support; Do NOT install any extra app.
  • Other ways of sharing printers: With Samba, Google Cloud Print.

Add Printer: Fuji Xerox DocuPrint M205 f

Choose the recommended 'Make and Model': Fuji Xerox DocuPrint M215 Foomatic/foo2hbpl2.

[Obsolete] Install Manually when .deb Package Not Available

Follow instructions from http://foo2zjs.rkkda.com/
$ wget http://foo2zjs.rkkda.com/foo2zjs.tar.gz
$ tar xf foo2zjs.tar.gz
$ cd foo2zjs
$ make
$ sudo make install
Choose Make and Model: Fuji Xerox WorkCentre 3045 Foomatic/foo2hbpl2

Video Processing

Include SRT Subtitle Into MKV

$ mkvmerge -o <output.mkv> <input.mkv> <subtitle.srt>

Miscellaneous

BOINC Headless Client

$ sudo apt install boinc-client
$ sudo vi /var/lib/boinc-client/remote_hosts.cfg
(Add the IP addresses of the remote hosts that are allowed to connect and to control the client via GUI RPCs.)

To control the BOINC client, install BOINC manager on the remote hosts.
$ sudo apt install boinc-manager
$ boincmgr -n hostname_or_IP_address
Or in BOINC Manager: File > Select computer...

Create Database & User via Command Line

$ sudo mysql
> CREATE DATABASE dbname;
> GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost' IDENTIFIED BY 'password';
> exit

Database Backup

For small database, can run this simple script periodically with cron to backup and upload it to another place.
#!/bin/sh
DT=$(date -u +%Y%m%d%H%M%S)
DBFILEPATH=/tmp/db_incr_${DT}.txt

rm /tmp/db_incr*
# Full Backup
# mysqldump -u xxxx -pxxxx db_xxxx > db_xxxx.sql
# Incremental Backup, if suitable
mysqldump -u xxxx -pxxxx --single-transaction db_xxxx table_one table_two table_three > ${DBFILEPATH}
xz -f ${DBFILEPATH}
# Upload... Can also use scp, curl, ...
ncftpput -f backup_xxxx_db.ncftp remote_server_dir ${DBFILEPATH}.xz
rm ${DBFILEPATH}.xz

Music Server

Computer installed with Music Player Daemon (MPD) becomes a music server, an audio player, or a jukebox.
$ sudo apt install mpd

Modify configuration file:
$ sudo cp /etc/mpd.conf /etc/mpd.conf.ORIG
$ sudo vi /etc/mpd.conf
(Modify these lines:)
music_directory  "/home/user/Music"  # Wherever your music is located
audio_output {
  type "alsa"
  name "My Jukebox"  # Name whatever you like
}

Restart the server.
$ sudo systemctl restart mpd

Now, you can run an MPD client on phones, tablets, or PCs to control the MPD.
I use M.A.L.P..

Reference:


PDFTK on Ubuntu 18.04

$ wget http://archive.ubuntu.com/ubuntu/pool/universe/p/pdftk/pdftk_2.02-4build1_amd64.deb
$ wget http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-6/libgcj17_6.4.0-8ubuntu1_amd64.deb
$ wget http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-defaults/libgcj-common_6.4-3ubuntu1_all.deb
$ sudo apt install ./pdftk_2.02-4build1_amd64.deb ./libgcj17_6.4.0-8ubuntu1_amd64.deb ./libgcj-common_6.4-3ubuntu1_all.deb 

Alternative download site for other architectures: http://mirrors.mit.edu/ubuntu-ports/pool/

No comments:

Post a Comment