A while ago I wrote a python library for parse and statistical analysis of network usage logs generated by net-acct.
A python was used for that implementation.
Later I began to learn Scala in order to make it closer to functional programming world. It seemed that writing simple log parser was an adequate task to take a feeling of language without experiencing extra difficulties.
A nice timing bonus makes me develop scala version futher and drop the python one.
python
real 2m32.052s
user 2m24.957s
sys 0m3.840s
scala
real 0m21.942s
user 0m15.653s
sys 0m0.456s
Tests were done on 6 Mb of gzipped logs with 1833.650 Mhz Athlon (3667.30 bogomips).
P.S. Improvements of configuration subsystem are now making Scala version useful for non-programmers. Documentation is still lacking, but I'm publishing it nevertheless.
2010-10-23
2010-07-26
A shortest complete list of packages that should be installed on a Debian system to repeat current configuration can be obtained by the following command:
To use output in scripting add a key: -F %p
This package list can be passed as an argument list an apt-get install program on your new system.
aptitude search '?installed?not(?automatic)?not(?reverse-depends(?installed))'
To use output in scripting add a key: -F %p
This package list can be passed as an argument list an apt-get install program on your new system.
2010-07-20
How to register your private key on the remote SSH server running on Linux
I've forgot which program from SSH toolchain does this (ssh-copy-id), and replaced it with my own method.
~/.ssh/id_dsa should be replaced with your private key file.
remote.org - SSH sever address
ssh-keygen -y -f ~/.ssh/id_dsa | ssh remote.org tee -a ~/.ssh/authorized_keys
~/.ssh/id_dsa should be replaced with your private key file.
remote.org - SSH sever address
2010-05-17
sudo in Debian squeeze
Debian squeeze creates an advanced config file for sudo package. File contains the following lines:
The first one allows all users from sudo group to do everything they want and the second one demonstrates a way to create a flexible sudo configuration.
%sudo ALL=(ALL) ALL
#includedir /etc/sudoers.d
The first one allows all users from sudo group to do everything they want and the second one demonstrates a way to create a flexible sudo configuration.
2010-05-12
Unattended shutdown
My notebook seems to have a hardware defect. It might self power on after being powered off for some time.
This bug quickly degrades the battery making me recharge it too often. To prevent the system from discharging the battery I've wrote the following startup script:
This script checks if a user is logged on in 30 seconds after system boot and if he is not, shuts the system down.
Commented lines at the top of the script are Debian LSB header that drives its new dependecy based boot system. This header requests starting the script after gdb making measured time interval for user to login more precise.
This bug quickly degrades the battery making me recharge it too often. To prevent the system from discharging the battery I've wrote the following startup script:
#!/bin/sh
### BEGIN INIT INFO
# Provides: haltIfNousers
# Required-Start:
# Required-Stop:
# Should-Start: gdm
# Default-Start: 2 3
# Default-Stop: 4 5
# Short-Description: Execute the halt command.
# Description:
### END INIT INFO
#Powers off the system if no user is logged in in 30 seconds
BLOCK_FILE=/tmp/haltIfNousers
case "$1" in
start)
$0 wait &
;;
wait)
touch "$BLOCK_FILE"
sleep 30
[ -e "$BLOCK_FILE" ] || exit 0
if ! who|grep '.*' -q ; then
echo $0: No users are logged in. Halting now.
shutdown -h now
exit 0
fi
rm -f "$BLOCK_FILE"
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
rm -f "$BLOCK_FILE"
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac
This script checks if a user is logged on in 30 seconds after system boot and if he is not, shuts the system down.
Commented lines at the top of the script are Debian LSB header that drives its new dependecy based boot system. This header requests starting the script after gdb making measured time interval for user to login more precise.
2010-04-12
Multiple make
To clean multiple folders at once:
echo base_path/{subfolder1,subfolder2} | xargs -n 1 make clean -C
2010-03-26
RPM atomated building
If your are providing sources or binaries of your software as RPMs you should be aware of a smart way of automating RPM creation.
To create RPM building environment:
In your RPM generation script use constructions like
Following this recommendation you will never need to force your packagers to use a harcoded SOURCES folder or to do configuration of your package with their RPM settings.
Again, thanks to comrade Buzykaev, for his tar command idea
To create RPM building environment:
- create ~/.rpmmacros with the following content:
%_topdir .../rpm #Arbitrary
%_tmppath /tmp/rpm #Optional
Three dots here denote your favorite RPM building directory infrastructure root. (/home/username will do) - use the following script:
#!/bin/sh
for d in _topdir _sourcedir _rpmdir _srcrpmdir _specdir _builddir _tmppath; do
mkdir -p `rpm --eval %{$d}`
done
In your RPM generation script use constructions like
# Doesn't override previously set value. See Parameter Expansion
SOURCES=${SOURCES:-`rpm --eval %{_sourcedir}`}
#Assumes your sources are in $PROJECTS/$PROJECT directory
tar --wildcards --exclude \*\.svn\* --exclude \*\~ \ -C "$PROJECTS" -zcf "$SOURCES/$PROJECT.tar.gz" $PROJECT
rpmbuild -ba "$PROJECTS/$PROJECT/$PROJECT.spec"
Following this recommendation you will never need to force your packagers to use a harcoded SOURCES folder or to do configuration of your package with their RPM settings.
2010-02-12
Bash versioning
Here is the bash command:
This expands to
This feature of bash is called Brace Expansion and can ease versioning of files based on filesystem. If you have a sequence of files with versions assigned to them as incremented part of the name, you can easily create one more with the given command:
Even nicer usage:
cp -i aaa/bbb/ccc/ddd/xxxx_{6,7}.tpl
This expands to
cp -i aaa/bbb/ccc/ddd/xxxx_6.tpl aaa/bbb/ccc/ddd/xxxx_7.tpl
This feature of bash is called Brace Expansion and can ease versioning of files based on filesystem. If you have a sequence of files with versions assigned to them as incremented part of the name, you can easily create one more with the given command:
> ls
aaa/bbb/ccc/ddd/xxxx_4.tpl
aaa/bbb/ccc/ddd/xxxx_5.tpl
aaa/bbb/ccc/ddd/xxxx_6.tpl
> cp -i aaa/bbb/ccc/ddd/xxxx_{6,7}.tpl
> ls
aaa/bbb/ccc/ddd/xxxx_4.tpl
aaa/bbb/ccc/ddd/xxxx_5.tpl
aaa/bbb/ccc/ddd/xxxx_6.tpl
aaa/bbb/ccc/ddd/xxxx_7.tpl
Even nicer usage:
cp filename{,_`date '+%F'`}
Подписаться на:
Сообщения (Atom)