Wednesday, August 31, 2016

Useful vimrc.local (remember last position of editing for vim)

vim /etc/vim/vimrc.local

" Jump to the last position
if has("autocmd")
autocmd BufReadPost * if line("'\"") > 0 && line ("'\"") <= line("$") | exe "normal! g`\"" | endif
endif

" Enable syntax hightlighting
syntax on

Debug systemd (show errors only) with journalctl

To see what failed on system startup:

root@vm-host1:~# journalctl -b -p 3
-- Logs begin at Wed 2016-08-31 12:28:11 MSK, end at Wed 2016-08-31 12:34:17 MSK. --
Aug 31 12:28:11 vm-host1 kernel: i8042: Can't read CTR while initializing i8042
Aug 31 12:28:11 vm-host1 kernel: sd 6:0:0:0: [sdd] No Caching mode page found
Aug 31 12:28:11 vm-host1 kernel: sd 6:0:0:0: [sdd] Assuming drive cache: write through
Aug 31 12:28:11 vm-host1 systemd-sysv-generator[306]: Ignoring creation of an alias umountiscsi.service for itself
Aug 31 12:28:12 vm-host1 kernel: Error: Driver 'pcspkr' is already registered, aborting...
Aug 31 12:28:24 vm-host1 iscsid[994]: iSCSI daemon with pid=995 started!


Wednesday, May 18, 2016

lsblk - best tool for auditing LVM (make graph of VG/PV)

# lsblk

NAME                            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                               8:0    1 819,7G  0 disk
|-sda1                            8:1    1   243M  0 part /boot
|-sda2                            8:2    1     1K  0 part
`-sda5                            8:5    1 819,5G  0 part
  |-server--vg-root             252:0    0   8,4G  0 lvm  /
  |-server--vg-swap_1           252:1    0    10G  0 lvm
  |-server--vg-var              252:2    0   2,8G  0 lvm  /var

Command to make sudo not to ask for password (bash one-liner)

By default Ubuntu users forced to type password every time when they perform root operations.
You can use this snippet to avoid it:

sed -i "/^%admin/ {/NOPASSWD/! s/ALL$/NOPASSWD:ALL/}" /etc/sudoers
sed -i "/^%sudo/ {/NOPASSWD/! s/ALL$/NOPASSWD:ALL/}" /etc/sudoers


Here is how to read it:
* find only strings that start with %admin
* skip them if they already contain NOPASSWD
(so you can safely run this script many times)
* substitute last(on the line) matching of word "ALL" with NOPASSWD:ALL


Monday, February 8, 2016

SOLVED :error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown

You should specify which secure protocol you would like to use, e.g. :

openssl s_client -showcerts -connect 10.100.1.17:443 -tls1

(I used Google Chrome to determine which protocol is definitely working, it's shown in the Connection information tab)

Friday, January 8, 2016

Linux(Centos/Ubuntu). Bash history search like in FreeBSD(tcsh)

echo '"\e[A": history-search-backward' >> /etc/inputrc
echo '"\e[B": history-search-forward' >> /etc/inputrc

bind -f /etc/inputrc


You'll find it wonderful! Definitely! It makes search in your bash history really simple. When you type just few first symbols of previously entered command and press arrow keys to get it back and thus avoiding typing of the whole line again and again every time.

Much more fancier than ctrl+r.

Ubuntu. Use vi(vim) within sudo.

ln -sf `which vim` /etc/alternatives/editor

Wednesday, January 6, 2016

Daily backups of all mysql databases (shell script with a fancy date format and retention period)

#!/bin/sh

BACKUP_DIR="/mnt/nfs_backup/backups/mysqldumps"

# Keep daily and ad-hoc backups separately
mkdir -p $BACKUP_DIR/daily
mkdir -p $BACKUP_DIR/longterm

# Perform backup of all databases
# --single-transaction option is used to make "consistent state of the database at the time when START TRANSACTION was issued without blocking any applications."
# --events option is used to avoid warnings (being sent via email from cron). It's for "Event Scheduler events for the dumped databases"
mysqldump --single-transaction --all-databases --events | gzip -9 > $BACKUP_DIR/daily/mysqldump_alldatabases_`date +"%Y%m%d_%H%M%S"`.sql.gz

# Keep daily backups for 20 days
find $BACKUP_DIR/daily -mtime +20 -type f -name "*sql.gz" -exec /bin/rm -rf {} \;