четверг, 25 августа 2011 г.

Как рекурсивно поменять права только каталогам или только файлам

cd /home/some_dir
chmod -R 644 *
find . -type d -exec chmod 0755 {} ';'

#Эта команда рекурсивно пройдется по текущему (точка ".") каталогу и всем его подкаталогам и изменит права на 755 только у каталогов (-type d)
find . -type d -exec chmod 755 {} \;
#Похожим образом действуем и с файлами:
find . -type f -exec chmod 644 {} \;
#если необходимо применить действия только к определенным файлам, подходящим по маске, то действуем так:
find . -type f -name '*.htm*' -exec chmod 644 {} \;
#а если нужно применить команду только к файлам или каталогам определенного владельца, то -
fiind . -type d -user fileowner -exec chmod 0755 {} \;

четверг, 18 августа 2011 г.

bash howto's

first line:
#!/bin/bash

#input parameters count:
$#

#script parameters:
$0 - self name, $1 ... $9 - input params

#check that file exist, the spaces near "[" and "]" are required :
if [ -e "streamcount.info" ]
then
echo 'file exist info'
fi

#get file extension:
SHORTFILENAME=$(basename $FULLFILENAME)
DEST_EXT=${SHORTFILENAME##*.}

#get temporary file name:
TFILE="/tmp/streaminfo.$RANDOM.$$.tmp"

#working directory:
$PWD

#redirect error stream to console and filter strings that contain word "Stream":
ffmpeg -i "$SRC" 2>&1 | grep "Stream"
#count strings with grep -c and put it into variable:
a=$( cat < $TFILE | grep -c "Audio:" )

#save command result as array with ( $( ) ):
s=( $( cat < $TFILE | grep "Audio:" | cut -f 2 -d "#" | cut -f 1 -d "(" ) )

#print array contents:
echo "stream numbers: ${s[@]:0}"

#use "for" construction:
for i in `seq 2 $a`;
do
index=$( echo "$i-1" | bc )
v="${s[index]}"
echo "$i. $v"
done

#extract float value:
x=$( echo "qwerty: 123.123123 !" | sed "s/.*[^0-9]\([0-9]\.[0-9]*\).*/\1/g" )

#float point operations:
echo "(256 / $x) / 10" | bc
for float result:
bc -l


# Checks for root privileges
if [ "$(whoami)" != 'root' ]
then
echo "You need to be root to execute uphosts. Exiting!"
exit 1
fi

# Checks required packages
ABORT=0
builtin type -P wget &>/dev/null || { echo -n "wget is missing."; ABORT=1; }
builtin type -P unzip &>/dev/null || { echo -n "unzip is missing."; ABORT=1; }
builtin type -P fromdos &>/dev/null || { echo -n "fromdos(tofrodos) is missing."; ABORT=1; }
builtin type -P grep &>/dev/null || { echo -n "grep is missing."; ABORT=1; }
if [ $ABORT != 0 ]
then
echo " Exiting!"
exit 2
fi

среда, 4 мая 2011 г.

startkde fail

After some compilation with slackware 13.37 kde start failed with message "Could not start ksmserver. Check your installation.".

Fix (link):
In /usr/bin/startkde, change the line similar to
LD_BIND_NOW=true /usr/lib/kde4/libexec/start_kdeinit_wrapper +kcminit_startup
by removing the LD_BIND_NOW=true clause, leaving just
/usr/lib/kde4/libexec/start_kdeinit_wrapper +kcminit_startup

четверг, 21 апреля 2011 г.

script for repository.slacky.eu download

#!/bin/sh
date +"%F %X %Z" >> .update
rm ./FILELIST.TXT
wget http://repository.slacky.eu/slackware-13.1/FILELIST.TXT
cat FILELIST.TXT | cut -d '.' -f2-20 -s | sed '/^$/d'| sed 's/^/slackware-13.1/' >./links.txt
wget --base="http://repository.slacky.eu/" -x --input-file=./links.txt -P pub -T 120 -t 3 -nc

вторник, 1 февраля 2011 г.

Parse OpenStreetMap data

Task:
Parse http://planet.openstreetmap.org/planet-110112.osm.bz2 and put data into DB
Technologies:
C#, SevenZipSharp, XML, XSD
Design:
Create data types with xsd.exe
Read data with SevenZipExtractor to WindowedStream (SharpDevelop ring buffer)
Mix DOM and SAX xml processing:
  • Read elements with XmlReader
  • Parse them with XmlSerializer
  • Put result in DB with BlToolkit