Resim arşivinden backup DVD oluşturmak

Ekim 24, 2017 § Yorum yok § Kalıcı bağlantı

Öncelikle DVD olacak büyüklükte tar dosyalarını ve pariteleri oluşturalım

cd hatiralar
for i in `find ./   -maxdepth 1  -mindepth 1 -type d`; do tar -cv $i| split -b 3584MB - "${i}_tar_cv.part_"; done;
for i in `find ./   -maxdepth 1  -mindepth 1 -name '*tar_cv.part*'`; do par2 create -r20 $i; done;

Daha sonra yapilan işlemler sıra ile

md5sum dvd2/* >> hatiralar_dvd17.txt
cp hatiralar_dvd17.txt dvd1/
mkisofs -o ../iso/dvd13.iso -J /home/fatiho/dvd_hatiralar/dvd2/*
dvdisaster -c -i /home/fatiho/dvd_hatiralar/iso/dvd13.iso  -e /home/fatiho/dvd_hatiralar/iso/dvd13.ecc
growisofs -dvd-compat -speed=12 -Z /dev/sr0=/home/fatiho/dvd_hatiralar/iso/dvd12.iso

Bu işleri tek satırda yapmak için :

for i in `find ./   -maxdepth 1  -mindepth 1 -type d -name 'dvd*'`; do adi=`basename $i`; echo $adi;echo $i; md5sum $i/* >> "hatiralar_${adi}.txt";cp "hatiralar_${adi}.txt" $i/; mkisofs -o  "/home/fatiho/dvd_hatiralar/iso/${adi}.iso" -J $i/*; dvdisaster -c -i "/home/fatiho/dvd_hatiralar/iso/${adi}.iso"  -e "/home/fatiho/dvd_hatiralar/iso/${adi}.ecc"; done;

Multicast trafiği dinleme

Ekim 24, 2017 § Yorum yok § Kalıcı bağlantı

Iperf server
route add -host 239.255.1.3 ethx (where x is the interface used to transmit/receive multicast traffic)
iperf -s -B 239.255.1.3 -u -f m -i 5 – This command will run iperf in server mode. It will to join multicast group 239.255.1.3 and receive 1470 byte UDP datagrams from the client once the client is started. Rates will be formatted in Mbps and will be reported every 5 seconds.

root@perf138:iperf-2.0.4# iperf -s -B 239.255.1.3 -u -f m -i 5
------------------------------------------------------------
Server listening on UDP port 5001
Binding to local address 239.255.1.3
Joining multicast group  239.255.1.3
Receiving 1470 byte datagrams
UDP buffer size: 8.00 MByte (default)
------------------------------------------------------------
[  3] local 239.255.1.3 port 5001 connected with 10.4.2.139 port 32952
[ ID] Interval       Transfer     Bandwidth       Jitter   Lost/Total Datagrams
[  3]  0.0- 5.0 sec    570 MBytes    957 Mbits/sec  0.017 ms    0/406906 (0%)
[ ID] Interval       Transfer     Bandwidth       Jitter   Lost/Total Datagrams
[  3]  5.0-10.0 sec    570 MBytes    957 Mbits/sec  0.015 ms    0/406894 (0%)
[ ID] Interval       Transfer     Bandwidth       Jitter   Lost/Total Datagrams
[  3] 10.0-15.0 sec    570 MBytes    957 Mbits/sec  0.016 ms    0/406905 (0%)
[ ID] Interval       Transfer     Bandwidth       Jitter   Lost/Total Datagrams
[  3] 15.0-20.0 sec    570 MBytes    957 Mbits/sec  0.018 ms    0/406891 (0%)
[ ID] Interval       Transfer     Bandwidth       Jitter   Lost/Total Datagrams
[  3] 20.0-25.0 sec    570 MBytes    957 Mbits/sec  0.013 ms    0/406897 (0%)
[ ID] Interval       Transfer     Bandwidth       Jitter   Lost/Total Datagrams
[  3] 25.0-30.0 sec    570 MBytes    957 Mbits/sec  0.010 ms    0/406907 (0%)
[ ID] Interval       Transfer     Bandwidth       Jitter   Lost/Total Datagrams
[  3]  0.0-30.0 sec  3423 MBytes    957 Mbits/sec  0.026 ms    0/2441426 (0%)

root@perf138:iperf-2.0.4#

Iperf client
route add -host 239.255.1.3 ethx (where x is the interface used to transmit/receive multicast traffic)
iperf -c 239.255.1.3 -u -b 957m -f m -i 5 -t 30 – o This command will run iperf in client mode. It will transmit 1470 byte UDP datagrams to destination address 239.255.1.3 at a rate of 957 Mbps. The test will terminate after 30 seconds. Rates will be formatted in Mbps and will be reported every 5 seconds.

root@perf139:iperf-2.0.4# iperf -c 239.255.1.3 -u -b 990m -f m -i 5 -t 30
------------------------------------------------------------
Client connecting to 239.255.1.3, UDP port 5001
Sending 1470 byte datagrams
Setting multicast TTL to 1
UDP buffer size: 0.06 MByte (default)
------------------------------------------------------------
[  3] local 10.4.2.139 port 32952 connected with 239.255.1.3 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 5.0 sec    570 MBytes    957 Mbits/sec
[ ID] Interval       Transfer     Bandwidth
[  3]  5.0-10.0 sec    570 MBytes    957 Mbits/sec
[ ID] Interval       Transfer     Bandwidth
[  3] 10.0-15.0 sec    570 MBytes    957 Mbits/sec
[ ID] Interval       Transfer     Bandwidth
[  3] 15.0-20.0 sec    570 MBytes    957 Mbits/sec
[ ID] Interval       Transfer     Bandwidth
[  3] 20.0-25.0 sec    570 MBytes    957 Mbits/sec
[ ID] Interval       Transfer     Bandwidth
[  3] 25.0-30.0 sec    570 MBytes    957 Mbits/sec
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-30.0 sec  3423 MBytes    957 Mbits/sec
[  3] Sent 2441428 datagrams
root@perf139:iperf-2.0.4#

Saniye bazında cronjob vermek

Şubat 25, 2015 § Yorum yok § Kalıcı bağlantı

Bildiğimiz gibi cronjoblar dakika olarak verilebilir.
Saniye bazında vermek için basit bir çözüm.
30 saniyede bir çalışan cronjob:

* * * * * /home/xxxx/1.sh
* * * * * (sleep 30; /home/xxxx/1.sh)

CVE-2014-6271 shellshock uygulaması

Şubat 25, 2015 § Yorum yok § Kalıcı bağlantı

Web Sitesi Performansını Ölçmek

Şubat 25, 2015 § Yorum yok § Kalıcı bağlantı

curl kullanalım
-w: write
-s: silent
-o: output

curl -w "Connect time: %{time_connect} Time to first byte: %{time_starttransfer} Total time: %{time_total} \n" -o /dev/null www.google.com
Connect time: 0.402 Time to first byte: 0.453 Total time: 0.475

Benzer şekilde curl-format dosyasi oluşturalim
içeriği:

\n
            time_namelookup:  %{time_namelookup}\n
               time_connect:  %{time_connect}\n
            time_appconnect:  %{time_appconnect}\n
           time_pretransfer:  %{time_pretransfer}\n
              time_redirect:  %{time_redirect}\n
         time_starttransfer:  %{time_starttransfer}\n
                            ----------\n
                 time_total:  %{time_total}\n
\n

daha sonra curl çalıştırırsak

curl -w "@curl-format" -o /dev/null -s http://www.google.com/
            time_namelookup:  0.416
               time_connect:  0.435
            time_appconnect:  0.000
           time_pretransfer:  0.435
              time_redirect:  0.000
         time_starttransfer:  0.488
                            ----------
                 time_total:  0.491

Process RAM kullanımını ölçmek

Şubat 25, 2015 § Yorum yok § Kalıcı bağlantı

Aşağıdaki komut bu iş için kullanılabilir:

ps -A -o pid,rss,command | grep nginx | grep -v grep | awk '{total+=$2}END{printf("nginx=%dMb\n", total/1024)}'

Burada RSS yerine VSZ’ye de bakılabilir.
RSS: Process tarafından o an kullanılan RAM miktarı.(kb cinsinden)
VSZ: Process doğduğunda ona çalışması için ayrılan RAM miktarı. (kb cinsinden)

vpnbook.com Sitesinden VPN Şifresini Otomatik Almak

Şubat 2, 2015 § Yorum yok § Kalıcı bağlantı

vpnbook güzel bir hizmet veriyor fakat şifrelerini belirsiz aralıklarla güncelliyorlar.
vpnbook.com dan şifreleri otomatik almak için ben vpnbook-utils kullanıyorum.

crontab’a aşağıdaki scripti koydum.

[root@FOZTURK vpnbook-utils-master]# crontab -l
9 */3 * * * /root/vpnbook.sh

vpnbook programının kodu:

[root@FOZTURK vpnbook-utils-master]# cat vpnbook 
#!/bin/sh
# The MIT License (MIT)
# Copyright (c) 2014 Tobias Bell <tobias.bell@gmail.com>

PROGRAM="vpnbook"
# URL to the site containing user and password
SITE="http://www.vpnbook.com/freevpn"
# URL to the site containing OpenVPN configs
OPENVPN_SITE="http://www.vpnbook.com"
# File where VPNBook credentials get stored
AUTH_FILE="./vpnbook.auth"
# Path to temporary file
AUTH_FILE_TMP="/tmp/vpnbook.$$"
# Folder where OpenVPN configs are created
CONFIG_FOLDER="./"
# Path to temporary folder for config generation
CONFIG_FOLDER_TEMP="/tmp/vpnbook-config.$$"

cleanup() {
        rm -f "$AUTH_FILE_TMP"
        rm -rf "$CONFIG_FOLDER_TEMP"
}

trap cleanup HUP INT TERM

usage() {
        cat << EOF
Usage: $PROGRAM <command> [parameter]

Commands are
    config  Generate OpenVPN configs for non-interactive usage based on configs provided
            on $OPENVPN_SITE
    auth    Extract user and password from $OPENVPN_SITE and save to auth-user-pass file
            (default: $AUTH_FILE)

Parameters are
    -a <file>    Path to the auth_user_pass file (default: $AUTH_FILE)
    -c <folder>  Folder where OpenVPN configs are generated (default: $CONFIG_FOLDER)
    -h           Show this help
EOF
}

download_site() {
        local site="$1"
        wget "$site" -q -O -
}

extract_credentials() {
        awk -F '[<>]' '
        BEGIN { exit_value = 1 }
        /Username:/ && !user_found { print $5; user_found = 1; next }
        /Password:/ && user_found { print $5; exit_value = 0; exit } 
        END { exit exit_value }
        '
}

extract_config_urls() {
        local site="$1"
        awk -F '[<>]' -v site=$site '
        /free-openvpn-account/ { split($4, a, /"/); print site a[2] }
        '
}

generate_auth() {
        local data="$1"
        if (echo "$data" | extract_credentials) > "$AUTH_FILE_TMP"; then
                mv "$AUTH_FILE_TMP" "$AUTH_FILE"
                chmod 600 "$AUTH_FILE"
        fi
}

generate_vpn_config() {
        awk -v auth_file="$AUTH_FILE" '
        # Remove windows newline
        { sub(/\r$/, "") }
        # Add both ports in config file and let OpenVPN select them remote-random
        /^remote/ {
                host = $2; print
                print $1, host, 25000
                if (!remote_random_printed) {
                        print "remote-random"
                        remote_random_printed = 1
                }
                next
        }
        # Switch authentication from interactive to file based
        /^auth-user-pass/ {
                print $1, auth_file
                print "auth-retry nointeract"
                next
        }
        # Let OpenVPN check the remote certificate
        /^<ca>/ {
                print "ns-cert-type server"
        }
        # Output everything else unchanged
        { print }
        '
}

generate_config() {
        local data="$1"
        mkdir "$CONFIG_FOLDER_TEMP" || return
        #Bu alanı ben kaldirdim
        cd /root/vpnbook_config/
        for url in $(echo "$site_data" | extract_config_urls "$OPENVPN_SITE"); do
                local file="$CONFIG_FOLDER_TEMP/${url##*/}"
                local conf_file="vpnbook-${file##*-}"
                conf_file=${conf_file%.zip}.ovpn
                conf_file="$CONFIG_FOLDER/$(echo $conf_file | tr 'A-Z' 'a-z')"
                wget "$url" -O "$file" -q
                unzip -p "$file"  '*udp53*.ovpn' | generate_vpn_config > "$conf_file"
        done

        wget "http://www.vpnbook.com/free-openvpn-account/VPNBook.com-OpenVPN-Euro1.zip"
        wget "http://www.vpnbook.com/free-openvpn-account/VPNBook.com-OpenVPN-Euro2.zip"

        unzip VPNBook.com-OpenVPN-Euro1.zip
        unzip VPNBook.com-OpenVPN-Euro2.zip
        rm -f VPNBook.com-OpenVPN-Euro1.zip
        rm -f VPNBook.com-OpenVPN-Euro2.zip
        generate_auth "$data"
}

main() {
        case $1 in
                config | auth )
                        generator_func="generate_$1"
                        ;;
                * )
                        usage
                        exit 1
                        ;;
        esac
        shift

        while getopts 'a:c:h' options; do
                case $options in
                        a )
                                auth_file=$OPTARG
                                ;;
                        c )
                                config_folder=$OPTARG
                                ;;
                        h | \?)
                                usage
                                exit 1
                                ;;
                esac
        done

        AUTH_FILE=${auth_file:-$AUTH_FILE}
        CONFIG_FOLDER=${config_folder:-$CONFIG_FOLDER}

        local site_data="$(download_site "$SITE")"
        $generator_func "$site_data"
        retval=$?
        cleanup
        return $retval
}

if [ "$PROGRAM" = ${0##*/} ]; then
        main "$@"
        exit $?
fi

echo Outputunun md5sum Sorunu

Ocak 30, 2015 § Yorum yok § Kalıcı bağlantı

echo ile çıkan stringi md5sum’a soktuğumuzda yanlış sonuç veriyor.
Bunun nedeni echo nun stringin sonuna “newline” \n eklemesidir.
Bu durumu düzeltmek için -n opsiyonunu kullanalim.

[fatih@FOZTURK ~]$ echo "deneme" | md5sum 
83ff036ac533544ddf84fb22edf62c2d  -
[fatih@FOZTURK ~]$ echo -n "deneme" | md5sum 
8f10d078b2799206cfe914b32cc6a5e9  -

Ubuntu’da vlc’yi root olarak çalıştırmak

Ocak 27, 2015 § Yorum yok § Kalıcı bağlantı

sed -i 's/geteuid/getppid/g' `which vlc`

Bash Saati

Ocak 20, 2015 § Yorum yok § Kalıcı bağlantı

function stopwatch(){
  date1=`date +%s`; 
   while true; do 
    echo -ne "$(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)\r"; 
    sleep 0.1
   done
}
stopwatch