How to redirect all stdout/stderr to syslog

An easy way to redirect all stdout/stderr to syslog is to do the following in a bash script:

exec 1> >(logger -t MYTAG) 2>&1

Please note this only works with bash as this is a bash extension to the POSIX standard.

If you want only stderr:

exec 2> >(logger -t MYTAG)

So if you have an application that runs on the foreground (and a good app should not daemonize), you can have the following shell script for a quick solution:

#!/bin/bash
exec 1> >(logger -t YADIYADA) 2>&1
exec /PATH/TO/APP

How to fix login issues with a password-less root MySQL user

If you installed MySQL without a root password, you will have difficulties to login as root. For example, you need to sudo first, and can’t login as a regular user.

The solution to this problem is to create a new root-like user like so:


CREATE USER admin@localhost IDENTIFIED BY 'SOME_PASSWORD';
GRANT ALL PRIVILEGES ON *.* TO admin@localhost WITH GRANT OPTION;

To allow this new user to login from another host, repeat the 2 commands above, replacing “localhost” with ‘%’. Please note that this is not recommended for security reasons.

How to install a Debian package non-interactively when it requires user input

Install the required package once manually, going through the configuration options you want. Then, do the following:

$ sudo apt install debconf-utils
$ sudo debconf-get-selections | grep MYPKG > MYPKG.CONF

To be able to re-install MYPKG to a new machine without any user input, copy the MYPKG.CONF file to the new machine and do the following:

$ sudo cat MYPKG.CONF | while read line; do echo "$line" | debconf-set-selections; done
$ sudo DEBIAN_FRONTEND=noninteractive dpkg -i MYPKG.deb

Tada! The package has been installed with the right configuration options without any user input.