Показаны сообщения с ярлыком linux. Показать все сообщения
Показаны сообщения с ярлыком linux. Показать все сообщения

среда, 5 октября 2016 г.

grep and awk like SQL


easy to understand if map *nix console tools to SQL commands.Its usefull to analyse big files with strict stucture, like logs or dumps.

select * from file where column = "keyword"
cat ./bigfile.log | fgrep "keyword"

select sum(numbers) from file where column = "keyword" 
cat ./bigfile.log | fgrep "keyword" |  awk '{a[$1]+=$2}END{for (i in a){print i,a[i]}}'

select avg(numbers) from file where column = "keyword"
cat ./bigfile.log | fgrep "keyword"  |  awk '{a[$1]["s"]+=$2; a[$1]["c"]+=1;}END{for (i in a){ print i,a[i]["s"]/a[i]["c"]} }'

select count(*) from file group by column
cat ./bigfile.log | perl -pe "s/^(REGEXP_PATTERN).*$/\$1/g"  |  sort | uniq -c

with perl or awk analyzing columns can be extracted from source file for further calculating.

group by date and calculating any speed/avg

for example your log file begin with date: 11:29:37.495 DEBUG - <SOME INFO>
gouping by date can be done by cutting chars from end
seconds: cat ./bigfile.log | cut -c -8  | uniq -c
minutes: cat ./bigfile.log | cut -c -5  | uniq -c







вторник, 1 сентября 2015 г.

compile tshark with custom lua

Linking with liblua failed.

lua: 5.1.4
wireshark: 1.12.2

1. download lua sources, download wireshark sources;
2. build shared library for lua
Edit Makefile fo building liblua.so.
You'll have to complete src/Makefile. Name the target, add it to the main list, and add a build rule, like this:

LUA_SO=liblua.so 

ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) $(LUA_SO)

$(LUA_SO): $(CORE_O) $(LIB_O)
    $(CC) -o $@ -shared $?

Also in the main Makefile, have the shared library installed along
with the static one:

TO_LIB= liblua.a liblua.so

3. run ./configure for wireshark with special flag for linker:
LDFLAGS="-ldl" ./configure --disable-wireshark --with-lua=/usr/local/

souces:
http://lua-users.org/lists/lua-l/2006-10/msg00091.html

понедельник, 14 октября 2013 г.

скриптуем математику в bash

юзается так:
$ seq 0 99 | ./test_seq.sh is_prime 

Сам скрипт выглядит так... Для проверки простых чисел используется калькулятор для командной строки o.0
#!/bin/bash

even_counter=$(( 2-$1%2  ))

function is_prime {
    number=
    if(( $1 < 0 )); then
        number=$(($1*-1))
    else
        number=$1
    fi
    if(( $number == 1 || $number == 0)); then
        echo $1
        return
    fi
    # а это строчка проверки числа, простое ли оно...
    result=`seq -s "*" 1 $(($number-1)) | 
sed -r "s/([0-9,\*]+)/(\1+1)%$number/" | bc`
    # перенос строчки чисто чтобы в блог нормально влезло

    #echo "[[$result]] for $number"
    if(( $result == 0 )); then
        echo $1
    fi
}

function is_even {
    if(( $even_counter == 2 )); then
        echo $1
        even_counter=1
    else
        even_counter=$(($even_counter + 1))
    fi
}

function is_not_even {
    if(( $even_counter == 1 )); then
        echo $1
        even_counter=$(($even_counter + 1))
    else
        even_counter=1
    fi
}

echo "filtering by: $1"
for item in $(cat)
do
    # echo "Item: $item"
    cmd="$1 $item"
    eval "$cmd"
    # eval $1
done

четверг, 11 июля 2013 г.

обновляем PHP до версии 5.4 в CentOS

Давно было пора это сделать, но всё какие-то другие дела отвлекали. как обычно вобщем.

Для начала удалим имеющееся старьё. php 5.2
yum uninstall php-common
Устанавливаем нужную версию
yum install php54
У нас nginx поэтому нужен FastCGI
yum install php54-fpm
Ну и то что постоянно используется
yum install php54-mysql 
yum install php54-gd
после установки не забыть в /etc/php.ini поставить short_open_tag = On
и перезапустить всё
/etc/init.d/php-fpm restart
/etc/init.d/nginx restart