Thursday, November 17, 2016

Summing numbers in a column

To sum several values in column from file we can use paste command and bash arithmetic expressions

$ echo $(($(paste -s -d'+' nums)))

I've always used tr to glue the values into one line, but the remaining '+' sign must be removed:

$ echo $(($(cat nums | tr '\n' '+' |sed 's/.$//')))

Or with awk:

$ awk '{s+=$1}; END { print s}' nums

Saturday, July 16, 2016

wget and line delimiters CR LF

If you download file with wget and the filename comes from windows file, the output filename will always have %0D at the end. To get rid of this, instead of:

wget $filename


wget $(echo "$filename" | tr -d '\r')

This will do the trick

Sunday, March 6, 2016

Raspberry Pi - booting into console mode

By default Raspbian boots into GUI mode. I don't need that. I wanted to change it to boot into command line. In Slackware or RedHat distros I always did it by editing runlevel in /etc/inittab.
Raspbian is different. I did it with raspi-config utility:

$ sudo raspi-config

And then I chose "Boot options"=>"B2 Console Autologin Text console, automatically logged in as 'pi' user"

Sunday, February 21, 2016

InsecureMag - downloading all issues

I bumped into InsecureMag ( - the free magazine on security. As I'm interested in it I decided to check it out. It's totally free. But being lazy I wanted to have all the issues on my harddisk. As usual bash comes with help:

for i in {1..49}; do
  wget -c "$link"

Have a nice reading :)

Raspberry Pi - Setting Static IP address

For Christmas I bought for myself :) Raspberry Pi and installed Raspbian and OpenELEC on this. For now I usually use it as low-energy  uploader/downloader or photo batch processor.
I want to have remote access to it also from outside my home network. By default Raspbian uses DHCP to obtain IP address from my home DHCP server. As I need to forward ports from my ISP router to my Raspberry PI, I need to give it always static IP address. I've been messing around with it a bit until I figured it out. Here is the recipe:

1. Turn off dhcp client which will always override things

$ sudo update-rc.d dhcpcd disable

You can also do it old school way by removing execute right:

$ sudo chmod a-x /etc/init.d/dhcpcd

2. Add the following lines to /etc/network/interfaces (the bold ones are new)

auto lo
auto eth0

iface lo inet loopback

#iface eth0 inet manuala
iface eth0 inet static

3. We need /etc/resolv.conf with static dns entry. This file is always rewritten by resolvconf utility, so we need to change it. In /etc/resolvconf.conf we add one line:


My nameserver is my gateway at the same time. 

4. Restart networking services by:

 $ sudo /etc/init.d/networking restart

Works for me. We can check if everything is ok running:

$ /sbin/ifconfig

Saturday, January 9, 2016

Checking the proxy servers

Sometimes we need some privacy on the web. So I needed good proxy servers. I googled a bit and found good list of them here:

But checking them one by one is boring, so I copied the interesed one into the file called list (copy/paste interesting fragments from web browser :):|80|flagCanada|80|flagBrazil|18000|flagChina|3128|flagUK|3128|flagCzechia

There are some environment variables called http_proxy and https_proxy. We can set them system-wide to use proxy like this:

export http_proxy="http://host:port"


export http_proxy="http://username:pass@host:port"

if proxy requires autentication.

So to check if proxy works we just need to set this env. variable and try to download something with wget. We can do this in the loop and get this list as input

--- cut ---


for l in $(cat list); do
HOST=$(echo $l | cut -f1 -d '|')
PORT=$(echo $l | cut -f2 -d '|')

export http_proxy="http://${HOST}:${PORT}"
export https_proxy=$http_proxy

wget -T 10 -O ${n}.jpg

unset http_proxy
unset https_proxy


--- cut ---

-T means timeout
-O means name of the output file

This way I got several files numberd as proxy server position on the list. The 0 size ones are non-working proxies.

-rw-r--r--  1 pi pi     0 Jan  9 17:56 10.jpg
-rw-r--r--  1 pi pi 20216 Jun 12  2013 1.jpg
-rw-r--r--  1 pi pi     0 Jan  9 19:23 2.jpg
-rw-r--r--  1 pi pi 20216 Jun 12  2013 3.jpg
-rw-r--r--  1 pi pi     0 Jan  9 19:23 4.jpg
-rw-r--r--  1 pi pi     0 Jan  9 19:23 5.jpg