Redirecting output of the bash keyword time

time command > timelog doesn’t work, because time outputs to stderr
time command 2> timelog doesn’t work either, because time actually is a bash keyword, and it’s always run in a subshell

Redirecting the output of time can be achieved by executing the whole command in a block, then redirecting its output:
{ time command; } 2> timelog

Note: Linux also provides a time binary (/usr/bin/time), but with a different output (and might be less efficient ?)

source

Convert a pkcs12 to pem (ca crt, crt, key)

$ openssl pkcs12 -in pkcs12file.p12 -out pemfile.pem
(by default, pkcs12 will ask for an import password, to decrypt the p12 file (just press Enter if you don’t have a password), and finally a passphrase to encrypt your key)

pemfile.pem now contains your CA certificate, your client certificate, and your (encrypted) key.

Lock all MySQL databases

Lock a database:
$ mysql -u user -p
mysql> FLUSH TABLES WITH READ LOCK;
This closes all open tables and locks all tables for all databases with a read lock until you execute UNLOCK TABLES.

Unlock:
mysql> UNLOCK TABLES;

(to lock a single table: LOCK TABLES table READ;)

Cleaning Apple Mail’s Envelope Index

Apple Mail keeps a lot of junk in a SQLite database named Envelope Index. Since it’s a database, it tends to grow with time, and deleted records are not handled very efficiently. You might want to clean it a bit from time to time, and Mail might even seem a little faster after that.

1. Quit Mail

2. Launch a terminal, and type this command :

sqlite3 ~/Library/Mail/Envelope\ Index vacuum

source

Resolving apt-get gpg issues

You run apt-get update, and it complains about some missing key IDs:

W: There is no public key available for the following key IDs:
B5D0C804ADB11277
W: GPG error: http://volatile.debian.org etch/volatile Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY EC61E0B0BBE55AB3
W: You may want to run apt-get update to correct these problems

B5D0C804ADB11277 and EC61E0B0BBE55AB3 are the missing gpg pub keys. Fetch them with gpg, and import them into apt :

gpg --keyserver subkeys.pgp.net --recv-key B5D0C804ADB11277
gpg -a --export B5D0C804ADB11277 | apt-key add -
apt-get update

OR (new and improved!)

apt-key advanced --keyserver subkeys.pgp.net --recv-keys B5D0C804ADB11277
apt-get update

or, with a different server: apt-key advanced --keyserver pgp.mit.edu --recv-keys

Recover mysql root password

– Stop mysql
# /etc/init.d/mysql stop

– Lauch mysql with –skip-grant-tables (WARNING: your mysql server will launch without any password authentication, so please protect it first with a firewall or something if it’s world accessible)
# mysqld_safe --skip-grant-tables

– Login as root without a password
$ mysql -u root

– Change the password
mysql> use mysql;
mysql> update user set password=PASSWORD("your_new_root_password") where User='root';
mysql> flush privileges;
mysql> quit

– Stop mysql
# /etc/init.d/mysql stop

– Start mysql again to re-enable authentication
# /etc/init.d/mysql start