Set transfer rate in proftpd 1.3.1

srv:~# cat /etc/proftpd/proftpd.conf | grep -i transferr
TransferRate                    RETR,STOR 5120 # 5 Mbit/s

Configure multicast routing on Debian with NAT

srv:/usr/src# wget http://downloads.sourceforge.net/project/igmpproxy/igmpproxy/0.1/igmpproxy-0.1.tar.gz
srv:/usr/src# cd igmpproxy/
srv:/usr/src/igmpproxy# ./configure && make && make install


Configure igmpproxy.conf:


srv:/usr/src/igmpproxy# cat /usr/local/etc/igmpproxy.conf | grep -v "^#"
quickleave
phyint eth0 upstream  ratelimit 0  threshold 1
        altnet 212.0.0.0/8
        altnet 213.0.0.0/8
phyint eth1 downstream  ratelimit 0  threshold 1
phyint ppp0 disabled
phyint eth2 disabled

srv:/usr/src/igmpproxy# 
igmpproxy -dv igmpproxy.conf
adding VIF, Ix 0 Fl 0x0 IP 0x0101000a eth1, Threshold: 1, Ratelimit: 0
adding VIF, Ix 1 Fl 0x0 IP 0x0101010a eth0, Threshold: 1, Ratelimit: 0
joinMcGroup: 224.0.0.2 on eth1
RECV Membership query   from 10.0.1.1        to 224.0.0.1
RECV Membership query   from your_ext_ip     to 224.0.0.1
RECV V2 member report   from 10.0.1.1        to 224.0.0.2
The IGMP message was from myself. Ignoring.
The IGMP message was from myself. Ignoring.
RECV V2 member report   from 10.0.1.3        to 239.255.255.250
Inserted route table entry for 239.255.255.250 on VIF #0
joinMcGroup: 239.255.255.250 on eth0
RECV V2 member report   from 10.1.1.1        to 239.255.255.250
...
etc


Configure iptables:


srv:/# cat /etc/init.d/firewall | grep 224
insert ("-t filter -A INPUT -d 224.0.0.0/240.0.0.0 -i eth0 -j ACCEPT");
insert ("-t filter -A INPUT -s 224.0.0.0/240.0.0.0 -i eth0 -j ACCEPT");
insert ("-t filter -A FORWARD -d 224.0.0.0/240.0.0.0 -j ACCEPT");
insert ("-t filter -A FORWARD -s 224.0.0.0/240.0.0.0 -j ACCEPT");
insert ("-t mangle -A PREROUTING -d 224.0.0.0/240.0.0.0 -p udp -j TTL --ttl-inc 1");


TODO: start-stop daemon

Rebuild squid3 package with --disable-internal-dns option in Debian

srv:/# apt-get install devscripts build-essential fakeroot 
srv:/# apt-get build-dep squid3 
srv:/# cd /usr/src && apt-get source squid3
srv:/usr/src# nano squid3-3.0.STABLE8/debian/rules 

 Добавить --disable-internal-dns в опции.

srv:/usr/src# cd squid3-3.0.STABLE8/ && debuild -us -uc && cd ..
srv:/usr/src# ls | grep deb
squid3_3.0.STABLE8-3+lenny4_amd64.deb 
squid3-cgi_3.0.STABLE8-3+lenny4_amd64.deb 
squid3-common_3.0.STABLE8-3+lenny4_all.deb squidclient_3.0.STABLE8-3+lenny4_amd64.deb
srv:/usr/src# dpkg -i squid3_3.0.STABLE8-3+lenny4_amd64.deb
Выбор ранее не выбранного пакета squid3.
(Чтение базы данных... на данный момент установлено 40276 файлов и каталогов.)
Распаковывается пакет squid3 (из файла squid3_3.0.STABLE8-3+lenny4_amd64.deb)...
Настраивается пакет squid3 (3.0.STABLE8-3+lenny4) ...


Файл конфигурации `/etc/squid3/squid.conf'
 ==> Изменён после установки (вами или сценарием).
 ==> Автор пакета предоставил обновлённую версию.
  Что вы будете с этим делать?  У вас есть следующие варианты:
   Y или I : установить версию, предлагаемую сопровождающим пакета
   N или O : оставить установленную на данный момент версию
      D    : показать различия между версиями
      Z    : перевести этот процесс в фоновый режим для проверки ситуации
 По умолчанию сохраняется текущая версия файла конфигурации.
*** squid.conf (Y/I/N/O/D/Z) [по умолчанию N] ?
Restarting Squid HTTP Proxy 3.0: squid3.
Обрабатываются триггеры для man-db ...
srv:/usr/src#


Добавить dns_children в squid.conf.

srv:/usr/src# /etc/init.d/squid3 restart
Restarting Squid HTTP Proxy 3.0: squid3 Waiting......done.
.
srv:/usr/src# ps aux | grep dns
proxy    12652  0.0  0.1  24320  1472 ?        Ss   18:31   0:00 (dnsserver)
proxy    12653  0.0  0.1  24320  1472 ?        Ss   18:31   0:00 (dnsserver)
proxy    12654  0.0  0.1  24320  1468 ?        Ss   18:31   0:00 (dnsserver)
proxy    12655  0.0  0.1  24320  1472 ?        Ss   18:31   0:00 (dnsserver)
proxy    12656  0.0  0.1  24320  1468 ?        Ss   18:31   0:00 (dnsserver)
proxy    12657  0.0  0.1  24320  1468 ?        Ss   18:31   0:00 (dnsserver)
proxy    12658  0.0  0.1  24320  1472 ?        Ss   18:31   0:00 (dnsserver)
proxy    12659  0.0  0.1  24320  1472 ?        Ss   18:31   0:00 (dnsserver)
proxy    12660  0.0  0.1  20152  1292 ?        Ss   18:31   0:00 (dnsserver)
proxy    12661  0.0  0.1  20152  1296 ?        Ss   18:31   0:00 (dnsserver)
root     15169  0.0  0.0   5892   756 pts/11   R+   18:42   0:00 grep dns

Fix mplayer sound delay with external AC3 sound track

posix@laptop:/mnt/nas/movies$ mplayer -audiofile movie.original.ac3 -audio-demuxer 20 -rawaudio format=0x2000 movie.avi -sub movie.rus.srt

squid-2.7.STABLE8 delay_pools speed limiting

[root@gw ~]# squid -v
Squid Cache: Version 2.7.STABLE8
configure options: '--bindir=/usr/local/sbin' '--sbindir=/usr/local/sbin' '--datadir=/usr/local/etc/squid' '--libexecdir=/usr/local/libexec/squid' '--localstatedir=/usr/local/squid' '--sysconfdir=/usr/local/etc/squid' '--enable-removal-policies=lru heap' '--disable-linux-netfilter' '--disable-linux-tproxy' '--disable-epoll' '--enable-auth=basic digest negotiate ntlm' '--enable-basic-auth-helpers=DB NCSA PAM MSNT SMB' '--enable-digest-auth-helpers=password' '--enable-external-acl-helpers=ip_user session unix_group wbinfo_group' '--enable-ntlm-auth-helpers=SMB' '--enable-storeio=ufs diskd null' '--enable-delay-pools' '--enable-snmp' '--enable-pf-transparent' '--enable-err-languages=Armenian Azerbaijani Bulgarian Catalan Czech Danish Dutch English Estonian Finnish French German Greek Hebrew Hungarian Italian Japanese Korean Lithuanian Polish Portuguese Romanian Russian-1251 Russian-koi8-r Serbian Simplify_Chinese Slovak Spanish Swedish Traditional_Chinese Turkish Ukrainian-1251 Ukrainian-koi8-u Ukrainian-utf8' '--enable-default-err-language=English' '--prefix=/usr/local' '--mandir=/usr/local/man' '--infodir=/usr/local/info/' '--build=i386-portbld-freebsd8.0' 'build_alias=i386-portbld-freebsd8.0' 'CC=cc' 'CFLAGS=-O2 -fno-strict-aliasing -pipe -march=pentium4 -mtune=pentium4 -march=pentium4' 'LDFLAGS=' 'CPPFLAGS='

squid.conf:
acl limited_speed src 10.20.5.0/24
http_access allow limited_speed
delay_pools 1
delay_class 1 1
delay_access 1 allow limited_speed
delay_access 1 deny all
delay_parameters 1 40960/40960

Configure ppp/pppoe in FreeBSD with standart facility

[root@gw /]# cat /etc/ppp/ppp.conf | grep -v -e "^#"
default:
set log Phase tun command

isp-name:
set device PPPoE:rl0
set authname your_login
set authkey your_password
set dial
set login
add default HISADDR

[root@gw /]# ppp -ddial isp-name

Fix Master Mono problem on VIA KT600 integrated AC97 sound chip with snd_via82xx module

Сегодня по невыясненным причинам неожиданно пропало управление каналом Master Mono в микшере, звук был, но очень тихий. Попытки реинициализации не помогли, проблема оказалась в каком-то баге, при котором сбрасываются значения микшера VIA DXS:
user@callisto:~$ amixer | tail -28
Simple mixer control 'VIA DXS',0
Capabilities: pvolume
Playback channels: Front Left - Front Right
Limits: Playback 0 - 31
Mono:
Front Left: Playback 31 [100%] [-99999.99dB]
Front Right: Playback 31 [100%] [-99999.99dB]
Simple mixer control 'VIA DXS',1
Capabilities: pvolume
Playback channels: Front Left - Front Right
Limits: Playback 0 - 31
Mono:
Front Left: Playback 31 [100%] [-99999.99dB]
Front Right: Playback 31 [100%] [-99999.99dB]
Simple mixer control 'VIA DXS',2
Capabilities: pvolume
Playback channels: Front Left - Front Right
Limits: Playback 0 - 31
Mono:
Front Left: Playback 31 [100%] [-99999.99dB]
Front Right: Playback 31 [100%] [-99999.99dB]
Simple mixer control 'VIA DXS',3
Capabilities: pvolume
Playback channels: Front Left - Front Right
Limits: Playback 0 - 31
Mono:
Front Left: Playback 31 [100%] [-99999.99dB]
Front Right: Playback 31 [100%] [-99999.99dB]

user@callisto:~$ for ((n=0; n<=3; n++)); do eval amixer sset "VIA\ DXS",$n 0dB; done
Simple mixer control 'VIA DXS',0
Capabilities: pvolume
Playback channels: Front Left - Front Right
Limits: Playback 0 - 31
Mono:
Front Left: Playback 31 [100%] [0.00dB]
Front Right: Playback 31 [100%] [0.00dB]
Simple mixer control 'VIA DXS',1
Capabilities: pvolume
Playback channels: Front Left - Front Right
Limits: Playback 0 - 31
Mono:
Front Left: Playback 31 [100%] [0.00dB]
Front Right: Playback 31 [100%] [0.00dB]
Simple mixer control 'VIA DXS',2
Capabilities: pvolume
Playback channels: Front Left - Front Right
Limits: Playback 0 - 31
Mono:
Front Left: Playback 31 [100%] [0.00dB]
Front Right: Playback 31 [100%] [0.00dB]
Simple mixer control 'VIA DXS',3
Capabilities: pvolume
Playback channels: Front Left - Front Right
Limits: Playback 0 - 31
Mono:
Front Left: Playback 31 [100%] [0.00dB]
Front Right: Playback 31 [100%] [0.00dB]

Quick enable internal microphone on Sony Vaio VGN-FZ140E snd-hda-intel

user@laptop:/$ lspci | grep -i audio
00:1b.0 Audio device: Intel Corporation 82801H (ICH8 Family) HD Audio Controller (rev 03)
user@laptop:/$ amixer cset numid=5,iface=MIXER,name='Capture Source' 1
numid=5,iface=MIXER,name='Capture Source'
  ; type=ENUMERATED,access=rw------,values=1,items=3
  ; Item #0 'Mic Jack'
  ; Item #1 'Internal Mic'
  ; Item #2 'PCM'
  : values=1
user@laptop:/$ amixer cset numid=4,iface=MIXER,name='Capture Switch' on
numid=4,iface=MIXER,name='Capture Switch'
  ; type=BOOLEAN,access=rw------,values=2
  : values=on,on

git fix commits messages

user@laptop:/mnt/sandbox/src/apstat$ git rebase -i c3e1531fe390a7867a36f283c0e161de2c424dce # parent
Rebasing (1/1)
You can amend the commit now, with

git commit --amend

Once you are satisfied with your changes, run

git rebase --continue

user@laptop:/mnt/sandbox/src/apstat$ git commit --amend apstat.py
Created commit 84a9cba: Fix: splitting and assigning cmd_list array in length check
1 files changed, 35 insertions(+), 39 deletions(-)
user@laptop:/mnt/sandbox/src/apstat$ git rebase --continue
Successfully rebased and updated refs/heads/master.
user@laptop:/mnt/sandbox/src/apstat$ git push --all origin
To git://git.yourdomain.ru/apstat.git
! [rejected] master -> master (non-fast forward)
error: failed to push some refs to 'git://git.yourdomain.ru/apstat.git'
user@laptop:/mnt/sandbox/src/apstat$ git pull
Merge made by recursive.
user@laptop:/mnt/sandbox/src/apstat$ git push --all origin
Counting objects: 2, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 562 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
To git://git.yourdomain.ru/apstat.git
6713dac..c32e9c3 master -> master
user@laptop:/mnt/sandbox/src/apstat$ git log
commit c32e9c37fb8302466293691827347ce9f908f3f3
Merge: 84a9cba... 6713dac...
Author: author
Date: Thu Apr 15 03:44:16 2010 +0400

Merge branch 'master' of git://git.yourdomain.ru/apstat

commit 84a9cbad7cba7c0dd204d12cfa7fb02a1e4043db
Author: author
Date: Thu Apr 15 02:44:31 2010 +0400

Fixed commit

[skip]

Apache stress test

[root@gw /usr/src]# ab -kc 10 -t 30 http://yourdomain.ru/
This is ApacheBench, Version 1.3d <$Revision: 1.73 $> apache-1.3
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking yourdomain.ru (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Finished 28396 requests
Server Software:        Apache                                             
Server Hostname:        yourdomain.ru
Server Port:            80

Document Path:          /
Document Length:        12054 bytes

Concurrency Level:      10
Time taken for tests:   30.001 seconds
Complete requests:      28396
Failed requests:        0
Broken pipe errors:     0
Keep-Alive requests:    28118
Total transferred:      350832390 bytes
HTML transferred:       342297438 bytes
Requests per second:    946.50 [#/sec] (mean)
Time per request:       10.57 [ms] (mean)
Time per request:       1.06 [ms] (mean, across all concurrent requests)
Transfer rate:          11694.02 [Kbytes/sec] received

Connection Times (ms)
min  mean[+/-sd] median   max
Connect:        0     0    0.7      0    60
Processing:     2    10    4.5     10   696
Waiting:        2    10    4.4     10   695
Total:          2    10    4.7     10   698

Percentage of the requests served within a certain time (ms)
50%     10
66%     10
75%     10
80%     10
90%     11
95%     11
98%     13
99%     20
100%    698 (last request)

watch hddtemp in screen

srv:/etc# screen -S hddtemp watch -n60 hddtemp /dev/sd{a,b,c,d}
[Ctrl a-d]
srv:/etc# screen -ls
There are screens on:
4446.hddtemp (14.04.2010 00:15:37) (Detached)
4439.sensors (14.04.2010 00:15:02) (Detached)
2 Sockets in /var/run/screen/S-root.
srv:/etc# screen -r hddtemp
Every 60,0s: hddtemp /dev/sda /dev/sdb /dev/sdc /dev/sdd MM DD HH:MM:SS YYYY
/dev/sda: ST380817AS: 27°C
/dev/sdb: ST3250824AS: 24°C
/dev/sdc: ST3250310AS: 27°C
/dev/sdd: ST3500630AS: 27°C

Recursively add file extension to all files

laptop:/srv# touch script{0..9}
laptop:/srv# ls
script0 script1 script2 script3 script4 script5 script6 script7 script8 script9
laptop:/srv# find . -type f -exec mv '{}' '{}'.sh \; ; ls
script0.sh script2.sh script4.sh script6.sh script8.sh
script1.sh script3.sh script5.sh script7.sh script9.sh
laptop:/srv# rm -f script* && touch script{0..9}
laptop:/srv# find . -type f -not -name "." -print0 | xargs -0 rename 's/(.)$/$1.sh/'; ls
script0.sh script2.sh script4.sh script6.sh script8.sh
script1.sh script3.sh script5.sh script7.sh script9.sh

mplayer keyboard shortcuts

<- and ->                               Seek backward/forward 10 seconds.
up and down                             Seek forward/backward 1 minute.
pgup and pgdown                         Seek forward/backward 10 minutes.
[ and ]                                 Decrease/increase current playback speed by 10%.
{ and }                                 Halve/double current playback speed.
backspace                               Reset playback speed to normal.
< and >                                 Go backward/forward in the playlist.
ENTER                                   Go forward in the playlist, even over the end.
HOME and END                            next/previous playtree entry in the parent list
INS and DEL (ASX playlist only)         next/previous alternative source.
p / SPACE                               Pause (pressing again unpauses).
.                                       Step forward. Pressing once will pause movie, every consecutive press will play one frame and then go into pause mode again (any other key unpauses).
q / ESC                                 Stop playing and quit.
+ and -                                 Adjust audio delay by +/- 0.1 seconds.
/ and *                                 Decrease/increase volume.
9 and 0                                 Decrease/increase volume.
( and )                                 Adjust audio balance in favor of left/right channel.
m                                       Mute sound.
_ (MPEG-TS and libavformat only)        Cycle through the available video tracks.
 
# (DVD, MPEG, Matroska, AVI and libavformat only) Cycle through the available audio tracks.
TAB (MPEG-TS only)                      Cycle through the available programs.
f                                       Toggle fullscreen (also see -fs). 
T                                       Toggle stay-on-top (also see -ontop).
w and e                                 Decrease/increase pan-and-scan range.
o                                       Toggle OSD states: none / seek / seek + timer / seek + timer + total time.
d                                       Toggle frame dropping states: none / skip display / skip decoding (see -framedrop and -hardframedrop).
v                                       Toggle subtitle visibility.
j                                       Cycle through the available subtitles.
y and g                                 Step forward/backward in the subtitle list.
F                                       Toggle displaying forced subtitles .
a                                       Toggle subtitle alignment: top / middle / bottom.
x and z                                 Adjust subtitle delay by +/- 0.1 seconds.
r and t                                 Move subtitles up/down.
i (-edlout mode only)                   Set start or end of an EDL skip and write it out to the given file.
s (-vf screenshot only)                 Take a screenshot.
S (-vf screenshot only)                 Start/stop taking screenshots.
I                                       Show filename on the OSD.
! and @                                 Seek to the beginning of the previous/next chapter.
D (-vo xvmc, -vf yadif, -vf kerndeint only) Activate/deactivate deinterlacer.
 
1 and 2                                 Adjust contrast.
3 and 4                                 Adjust brightness.
5 and 6                                 Adjust hue.
7 and 8                                 Adjust saturation.

Simple pseudo-console interface in python script


#!/usr/bin/env python

# copyright (c) 2010 vprokofyev.blogspot.com <v.prokofyev@gmail.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301 USA.

import sys
import string

class Console:
"""Create psedo-console terminal"""
 def f_prompt(self):
  print "Type 'help' or '?' to list available commands"
  done = False
  while not done:
   self.cmd = raw_input("> ")
   Parser.f_read_prompt()


class Parser:
"""Parse input from user"""
 def f_read_prompt(self):
  command_list = {'h':'help', '?':'?',
      's':'something',
      'q':'quit', 'e':'exit'}
  if Console.cmd in (command_list["h"], command_list["?"]):
   Info.f_usage()

  elif Console.cmd == command_list["s"]:
   CommandOutput.f_somefunction()

  elif Console.cmd in (command_list["q"], command_list["e"]):
   sys.exit()

  elif Console.cmd:
   print "Command not found"

class CommandOutput:
"""Init output"""
 def f_somefunction(self):
  print "Some output"

class Info:
"""Info"""
 def f_usage(self):
  print """
help/?        shows this help
something     print something
quit/exit     close program
"""

Console = Console()
Parser = Parser()
Info = Info()

Console.f_prompt()

git branch

callisto:/srv/sandbox/project$ git init
callisto:/srv/sandbox/project$ git add .
callisto:/srv/sandbox/project$ git commit -m 'Initial commit for master branch'
Created initial commit b2043e5: Initial comment for master branch
1 files changed, 36 insertions(+), 0 deletions(-)
create mode 100755 project.py
callisto:/srv/sandbox/project$ git remote add origin ssh://git.yourdomain.ru/srv/git/project.git
callisto:/srv/sandbox/project$ git push --all origin
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 680 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git://git.yourdomain.ru/srv/git/branch.git
* [new branch] master -> master
callisto:/srv/git/project# git branch -a
* master
origin/master

Switch project to another branch:

callisto:/srv/sandbox/project$ git init
Reinitialized existing Git repository in /srv/sandbox/project/.git/
callisto:/srv/sandbox/project$ git branch -r experimental
callisto:/srv/sandbox/project$ git branch -a
experimental
* master
origin/master
callisto:/srv/sandbox/project$ git checkout experimental
M project.py
Switched to branch "experimental"
callisto:/srv/sandbox/project$ git add .
callisto:/srv/sandbox/project$ git commit -m 'Initial commit for experimental branch'
Created commit 0a0f8cf: Initial commit for experimental branch
1 files changed, 54 insertions(+), 36 deletions(-)
rewrite project.py (98%)
callisto:/srv/sandbox/project$ git push --all origin
Counting objects: 5, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 1.12 KiB, done.
Total 3 (delta 0), reused 0 (delta 0)
To git://git.yourdomain.ru/srv/git/branch.git
* [new branch] experimental -> experimental
callisto:/srv/sandbox/project$ git branch -a
* experimental
master
origin/experimental
origin/master