Friday, July 10, 2020

Enjoying your Pi-hole on the go with Wireguard

If/once you've got a Raspberry Pi and installed Pi-hole at home, here's the next step:
https://www.pcmag.com/how-to/how-to-create-a-vpn-server-with-raspberry-pi

Skip OpenVPN and go for Wireguard.

Tested it on my cell phone reading google news. Win, no ads!

No need to transfer configuration files, you get a QR code on your Putty terminal to scan with your phone.

 

Tuesday, December 4, 2018

Budget gaming PC (~1000€) for Christmas 2018

CPU AMD Ryzen 5 2600X AM4 Box
Motherboards Gigabyte GA-AB350-Gaming
Ram Memory Corsair DDR 4 16G (8Gx2) 2400 CL14 Vengeance LPX Red CMK16GX4M2A2400C14R
Cases Corsair Carbide 100R Mid Tower Black
Power Supplies Corsair CX450M 450W PSU 80+ Bronze Modular
SSD Drives Samsung SSD 500GB 860 EVO M.2
Video Cards Sapphire RX 580 PULSE 8G GDDR5
Software Windows 10 Pro 64 Bit

This is the most cost effective PC I could come with for people with a relatively limited budget, still allowing to play the most recent games with more than acceptable performance.

Cost could be brought further down with small impact on performance by downgrading the CPU to AMD Ryzen 5 2600 (instead of the X version), Radeon RX 570 (instead of the 580), cheaper motherboard and ram etc.
I would stick with 16GB of RAM and at least 500GB of storage. Mechanical disks (aka HDD/spinners) are best avoided as they will cause a performance hit to your PC.

Tuesday, June 5, 2018

Bash - get flags and arbitrary strings in no particular order


#!/bin/bash

# Get arguments and separate them to flags and arbitrary strings
# Execution example: ./get_opts.sh Something -w 10 somethingElse -c20 whatever

# For debug purpose, show everything we received:
# echo $@

# Save original arguments for later use / debug purpose
original_arguments="$@"

# Initialize variable
strings=""

# While there are arguments, keep looping
while (( "$#" )); do
case "$1" in
# if the next argument begins with '-w'
-w*)
# Put all the digits in this or the next argument in  the variable 'warn' and shift the argument array
warn=$(echo $1|tr -cd  '[[:digit:]]')
if [ "$warn" ]; then shift 1;
else warn=$(echo $2|tr -cd  '[[:digit:]]'); shift 2;
fi
;;
# if the next argument beings with '-c'
-c*)
# put all the digits in this or the next argument in the variable 'crit' and shift the argument array
crit=$(echo $1|tr -cd  '[[:digit:]]')
if [ "$crit" ]; then shift 1;
else crit=$(echo $2|tr -cd  '[[:digit:]]'); shift 2;
fi
;;
*)
# Arbitrary strings go here
strings="${strings} $1"
shift
;;
esac
done
echo Warn=${warn} Crit=${crit} Arbitary strings=${strings}
exit

Sunday, November 15, 2015

Best inventory command like tool for linux!

I've been looking around for a nice tool to give me information about my machine. Yes, I know there's lspci etc etc etc, but these are pretty spamy, ugly and take a while to decipher. To the rescue comes inxi. To me it's exactly what I've been looking for. I run it like this:
# inxi -Fi
System:    Host: XXXXXXXXX Kernel: 3.16.0-30-generic x86_64 (64 bit) Console: tty 0 Distro: Ubuntu 14.04 trusty
Machine:   System: Xen product: HVM domU version: 4.1.5 serial: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
           Mobo: N/A model: N/A Bios: Xen version: 4.1.5 date: 06/14/2013
CPU:       Quad core Intel Xeon CPU E5645 (-HT-MCP-) cache: 12288 KB flags: (lm nx sse sse2 sse3 sse4_1 sse4_2 ssse3)
           Clock Speeds: 1: 2400.146 MHz 2: 2400.146 MHz 3: 2400.146 MHz 4: 2400.146 MHz
Graphics:  Card: Cirrus Logic GD 5446 X-Vendor: N/A driver: N/A tty size: 164x47 Advanced Data: N/A for root out of X
Network:   Card: Failed to Detect Network Card!
           WAN IP: 62.0.100.191 IF: eth0 ip: 192.168.3.202
Drives:    HDD Total Size: 64.4GB (2.5% used) 1: id: /dev/xvda model: N/A size: 64.4GB
Partition: ID: / size: 51G used: 1.5G (4%) fs: ext4 ID: swap-1 size: 8.85GB used: 0.00GB (0%) fs: swap
RAID:      No RAID devices detected - /proc/mdstat and md_mod kernel raid module present
Sensors:   None detected - is lm-sensors installed and configured?
Info:      Processes: 128 Uptime: 8 min Memory: 172.1/7979.7MB Runlevel: 2 Client: Shell (bash) inxi: 1.9.17

Thursday, October 29, 2015

Setting up multiple hard drives at once on Ubuntu

Sometimes you need to set up multiple hard drives sequentially, say for example for a Hadoop data node.
Here's how you do it quick and easy:
# for hdd in /dev/sd{c..h};do echo -e "n\n\n\n\n\nw\n\n"|fdisk $hdd;mkfs.ext4 ${hdd}1;done

In order to automount, use:
# blkid

Add/replace the UUID of the new HDD in /etc/fstab like the following examples:
UUID=b8923549-5794-4cad-89b3-0813fafb9566 /            ext4    errors=remount-ro 0       1
UUID=f0fc9526-0579-4116-994b-c79878f7f393 /hdfs/10    ext4    noatime 0    1

Changing UUID of an existing partition:
# tune2fs /dev/sdl1  -U d81ce3c1-27fa-4a37-8d61-3bebc7ac4e92

Extra options:
  • Enable writeback mode. This mode will typically provide the best ext4 performance.
# tune2fs -o journal_data_writeback /dev/sda10
  • Delete has_journal option
# tune2fs -O ^has_journal /dev/sda10

Sunday, April 13, 2014

Hadoop zookeeper connections CDH4

I'm currently running two hadoop clusters  (Cloudera CDH4) and both suffer from the same problem, stale zookeeper connections that choke it to death.
After digging around, I've located two culprits. One is the thrift hive server we run manually for Tableau connection and the other is Hue.
To make a long story short, here's my solution:

#!/bin/bash
# Function check thrift process id
check_pid() {
        pid=`cat ~/thrift.pid`
    #echo $pid
    ps -A|grep $pid|grep java > /dev/null 2>&1
        result=$?
}


# Function restart Hue service
restart_hue() {
    curl -X POST -u 'admin:admin' http://localhost:7180/api/v2/clusters/TEST%20-%20CDH4/services/hue1/commands/restart  >/dev/null 2>&1
}


# Function kill thrift server
kill_thrift() {
        kill $pid
        sleep 2
        check_pid
        if [ "$result" == 0 ]; then {
                kill -9 $pid
                sleep 2
        }
        fi
    check_pid
    if [ "$result" == 0 ]; then {
        echo "Error: Failed to kill server"
        exit 1
        }
    fi
}


# Sanity
if [ ! -f ~/thrift.pid ]; then {
    echo "Error: thrift process id file ~/thrift.pid not found."
    exit 1
}
fi


if [ `whoami` != "admin" ]; then {
    echo "Error: you are not logged in or executing as user admin, please do so."
    exit 1
}
fi


# Main
restart_hue
result=$?
if [ "$result" -gt 0 ]; then {
        echo Error restarting Hue service, please check cluster integrity.
        exit 1
}
fi
zookeeper_connections=`echo srvr|nc localhost 2181|grep -i connections`
result=$?
if [ "$result" -gt 0 ]; then {
    echo Error: no reply from Zookeeper.
    exit 1
}
fi
zookeeper_connections=${zookeeper_connections##*: }
#echo $zookeeper_connections
if [ $zookeeper_connections -gt 100 ]; then {
    echo "Zookeeper has $zookeeper_connections open conenctions."
    check_pid
    if [ "$result" -gt 0 ]; then {
        echo "Error: can not find thrift server PID"
        exit 1
    }
    fi   
    echo "Found Thrift server, restarting"
    kill_thrift
    export HIVE_PORT=10001
    hive --service hiveserver &
    pid=$!
    echo $pid> ~/thrift.pid
    return=$?
}
else {
    echo "Zookeeper has $zookeeper_connections open conenctions."
}
fi
exit $return
This script is executed every morning via crontab to keep zookeeper from choking. It's been running happily for a few months now :)

Emailing from Bash CLI or script on ubuntu

Basically what you might be looking for is a command line or shell script email sender that knows how to work with gmail. If you are, search no more!

$ sudo apt-get install msmtp openssl ca-certificates
$ vim ~/.msmtprc
account default
host smtp.gmail.com
port 587
from GMAIL_ACCOUNT
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
auth on
user GMAIL_ACCOUNT
password GMAIL_PASSWORD
logfile ~/.msmtp
$ chmod 600  ~/.msmtp

Prepare a file starting wit:
to: DESTINATION
from: SENDER
subject: SUBJECT

And finally:
msmtp -t < YOUR_FILE

Tuesday, April 8, 2014

Forcing Wacom Intous to work with a single monitor on dual monitor setup

So your Wacom Intous refuses to stay locked with a single monitor in your dual + monitor setup no matter what you tell it? There's a quick fix, in the Wacom driver properties, use manual resolution!
For example, to lock it to your left most screen on a FullHD setup put: 0x0 - 1919x1079 and voilà!

How to determine mysql table storage engine

So you're trying to find out which storage engine is being used by tables in your mysql database? Thank to Ronald Bradford's blog entry, the best answer I found is this:
mysql> use database_name;
mysql> SELECT table_name,engine FROM INFORMATION_SCHEMA.TABLES WHERE table_schema=DATABASE();

Monday, February 24, 2014

Switching keyboard layout on Ubuntu 13.10

Found this after digging around in AskUbuntu:
It's still possible to make the change from the command line using dpkg. Credit goes to this site: http://www.humans-enabled.com/2013/10/ubuntu-1310-enable-controlaltbackspace.html. To sum up what's written there, you can open a terminal and enter

$ sudo dpkg-reconfigure keyboard-configuration

This will take you through a series of options for the keyboard; for the first 4 or 5 just hit enter to keep things as is, and you'll end up with the option to enable Ctrl-Alt-Backspace.

Sunday, November 24, 2013

Quick ping-scanning a network using bash

So you want to know who answers to pings in said network or IP range?
Certainly not the best way to map a network, but it's useful enough to find a forgotten IP number without having to check with your DHCP:

$ for ip in 10.0.0.{000..255};do ping -c1 -t1 $ip > /dev/null 2>&1 && echo "${ip} is up" & done|grep up|sort

This method can also be used to run multiple commands in multiple terminal windows by using gnome-terminal -e "your command here".

Tuesday, October 8, 2013

Non interactive ftp for Linux users

FTP. Yes, people are still using it.

  1.  non interactive ftp login:
    $ ~/.netrc
    machine server_name/ip
    login username
    password password


    $ chmod 600 ~/.netrc
    Now you can simply ftp to said machine and it will auto-login.

  2.  Copying a file to the ftp server:
    • echo put FILE.ext | ftp server_name
      or
    •  curl -T FILE.ext ftp://server_name --user username:password

Wednesday, October 2, 2013

Checking your NIC is connected using bash

A simple yet effective way to test your network adapters connection status using  command line.

Requires: ethtool


# ifconfig -a|grep eth|while read line;do echo ${line%% *} && ethtool ${line%% *}|grep Link;done

Thursday, July 18, 2013

Slow ssh in RHEL/CentOS

It's everywhere and so it's also here, if ssh to Red Hat or CentOS takes forever, here's a quick fix:
# sed -i 's/^#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
# sed -i 's/^#GSSAPIAuthentication no/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
# sed -i 's/^GSSAPIAuthentication yes/#GSSAPIAuthentication yes/g' /etc/ssh/sshd_config
# service sshd restart

Monday, May 6, 2013

BASH CLI turn monitor off / blank screen

So you want to get your screen blank or get your monitor into standby mode from the CLI?
Add the following to your .bashrc:


alias blank='sleep 1 && xset dpms force standby'

From there on, just use the command blank from your terminal.

Saturday, April 6, 2013

Quickly add rules to IPTABLES on CentOS/RHEL 5.x using a script

Older iptables lack the -C switch so you have to use bash to check whether a rule already exists before appending it. Works like this:

if [ ! "`iptables-save | grep 'dport 21'`" ]; then iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT;fi
if [ ! "`iptables-save | grep 'dport 22'`" ]; then iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT;fi
if [ ! "`iptables-save | grep 'dport 80'`" ]; then iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT;fi
service iptables save
Probably not the most elegant solution, but it works. 

Quickly disable SELinux in a setup script

So we all know how to disable SELinux manually, but what about doing so as part of a setup script?
Easy, got to love sed!

Setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/sysconfig/selinux && cat /etc/sysconfig/selinux
Repeat on /etc/selinux/config for Centos 7

Wednesday, February 20, 2013

Wednesday, February 6, 2013

phpMyAdmin - Error

Don't you just love them errors? They make you stress your mind, check everything all over again, force to communicate with people around you and basically waste your time.

One such lovely error is:

Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.
There are quite a few answers online for fixing this problem but sometimes, especially if there's a chance you did something silly along the way, it just won't help.  So, yet another solution if everything else fails:

# chmod 0777 /var/lib/php/session

Monday, February 4, 2013

Apache cluster active server

So you have Apache running in a cluster and you want to know which server is active right now. PHP can help you there.

Put this line of code in whoami.php

<?php system('hostname', $retval); ?>