Eventually I get into producing something I think is useful for others. You'll find random technical knowledge in this Blog so please be patient and use the search function. Some of these software are rather lame and old, the list is ordered by the approximate age (newest first). Unfortunately my older stuff are lost or scattered around my old CDs, not readable anymore 8(.
The following shell script plays avi, mpeg and wmv files in a random order when executed in a directory containing files.
#!/bin/bash ls -1Q \ | awk 'BEGIN {FS="\n"} /.*.(avi|mpg|mpeg|wmv)/ {printf("%i\t%s\n",rand()*10^6,$1) }' \ | sort | cut -f2 | xargs mplayer -fs
A small shell script to convert singlepage A4-sized pdf documents to two pages per sheet using pstools.
#!/bin/bash function switch() { rm -f pdfopt.ps mv pdfopt2.ps pdfopt.ps } pdftops -paper A4 -level3 $1 pdfopt.ps psresize -p a4 pdfopt.ps pdfopt2.ps ; switch psnup -n2 -d1 -pa4 -Pa4 pdfopt.ps pdfopt2.ps ; switch psresize -pa4 pdfopt.ps pdfopt2.ps ; switch psresize -Pa4 pdfopt.ps pdfopt2.ps ; switch ps2ps pdfopt.ps pdfopt2.ps ; switch ps2pdf pdfopt.ps `basename $1 .pdf`_2.pdf rm -f pdfopt.ps
The PERL xmltv grabber for .hu and .ro packaged with the original xmltv distribution is rather slow and buggy so I've decided to write my own using AWK and of course bash.
#!/bin/bash WGET="wget -q -O- " get_channel_list() { list=`$WGET "http://www.port.hu/pls/tv/tv.channel?i_ch=1&i_days=1&i_xday=1&i_where=1"` # echo -e "$list" | egrep -zo '<select name="i_ch".*</select>' | awk '/value="[0-9]+">.*<\/option>/ { print $1 }' # echo -e "$list" | tr -d '\n' | egrep -o '<select name="i_ch".*</select>' | sed echo -e "$list" | awk '\ BEGIN{a=0} \ /<select name="i_ch"/{a=1} \ a==1 && /value/ { \ split($0,b,/value="/); \ chan=b[2] + 0; \ split($0,b,/value="[0-9]+">/); \ split(b[2],c,/<\/option>/); \ name=c[1]; \ print chan "\t" name; \ } \ /<\/select>/{a=0} \ ' | sort -n | sed "s/&/&/g" } channels=`get_channel_list` # print header cat <<EOF <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE tv SYSTEM "xmltv.dtd"> <tv source-info-url="http://www.port.hu/" source-data-url="http://www.port.hu" generator-info-name="XMLTV_MCREE" generator-info-url="http://www.tricon.hu/~mcree"> EOF # print channel list echo -e "$channels" | while read channel; do id=`echo -e "$channel" | cut -f1` name=`echo -e "$channel" | cut -f2` echo "<channel id=\"$id\">" echo " <display-name lang=\"hu\">$name</display-name>" echo "</channel>" done # get programmes for day in -1 +0 +1 +2 +3; do offset=$(( $day + 1 )) date=`date +%Y%m%d -d"now $day days"` nextdate=`date +%Y%m%d -d"now $day days"` zone=`date +%z` echo -e "$channels" | while read channel; do id=`echo -e "$channel" | cut -f1` name=`echo -e "$channel" | cut -f2` programmes=`$WGET "http://www.port.hu/pls/tv/tv.channel?i_ch=$id&i_days=$offset&i_xday=1&i_where=1"` echo -e "$programmes" | awk '\ /<tr/{tr=1} tr==1 && /<td.*<span class="btxt"/ {\ match($0,/([0-9]+:[0-9]+)/,a);\ split(a[1],d,/:/);\ if (d[1]!=0) {date="'$date'"} else {date="'$nextdate'"}; \ print "<programme start=\"" date d[1] d[2] "00 '$zone'\" channel=\"'$id'\">";\ getline;\ res=split($0,a,/(<[^>]*>)/);\ c=0;\ for (b=0;b<res;b++) \ if (a[b] ~ /\w/) \ if (c==0) {\ c=1; \ print "<title lang=\"hu\">" a[b] "</title>"\ } else {\ if (c==1) { c=2; print "<desc lang=\"hu\">"}\ print a[b]\ };\ if (c>1) print "</desc>"; \ print "</programme>"; \ }\ /<\/tr>{tr=0}/ ' | sed "s/&/&/g" done done # print footer cat <<EOF </tv> EOF
muddlestats.py.zip - My first somewhat serious python code that generates html statistics from muddleftpd server logs.
As a preparation for for establishing a distributed virtualized environment based on OpenVZ I had to create a new VE based on a precreated Debian Lenny x86 minimal OS template. Once the new VE had Internet access I took the time to update it and remove some unnecessary packages, reconfigure debconf to ask all questions then installed a basic LDAP environment:
dpkg-reconfigure debconf apt-get install slapd ldapscripts libapache2-mod-php5 php5-ldap cpu wbritish
The configuration values are mostly left intact. I've set the default password and DN (dc=example,dc=com) per se.
Then I've modified /etc/nsswitch.conf
to contain:
passwd: files ldap group: files ldap shadow: files ldap hosts: files dns ldap networks: files protocols: db files services: db files ethers: db files rpc: db files netgroup: nis
I've downloaded and configured PHP LDAP Admin:
wget "http://switch.dl.sourceforge.net/sourceforge/phpldapadmin/phpldapadmin-1.1.0.7.tar.gz"
Then I've created a shell script to migrate user accounts (1000<uid) and groups (1000<gid<80000) to the LDAP database inside my VE (id:100). Modify this script to match your own settings.
#!/bin/bash generate() { passwd=`cat /etc/passwd` shadow=`cat /etc/shadow` group=`cat /etc/group` echo -e "$passwd" | while read line; do name=`echo "$line" | cut -f 1 -d:` uid=`echo "$line" | cut -f 3 -d:` gid=`echo "$line" | cut -f 4 -d:` gecos=`echo "$line" | cut -f 5 -d: | recode l1..bs | tr -d "\b"` home=`echo "$line" | cut -f 6 -d:` shell=`echo "$line" | cut -f 7 -d:` if [ $uid -lt 1000 ]; then continue; fi passwd=`echo -e "$shadow" | egrep "^$name:" | cut -f2 -d:` cat <<EOF dn: cn=$name,ou=Users,dc=example,dc=com cn: $name objectClass: account objectClass: posixAccount objectClass: top uid: $name uidNumber: $uid gidNumber: $gid userPassword: {crypt}$passwd homeDirectory: $home loginShell: $shell gecos: $gecos EOF done echo -n "$group" | while read line; do name=`echo "$line" | cut -f 1 -d:` gid=`echo "$line" | cut -f 3 -d:` members=`echo "$line" | cut -f 4 -d:` if [ $gid -lt 1000 -o $gid -gt 80000 ]; then continue; fi cat <<EOF dn: cn=$name,ou=Groups,dc=example,dc=com objectClass: top objectClass: posixGroup cn: $name gidNumber: $gid EOF memuid="" echo -n "$members" | tr ',' "\n" | while read member; do echo "memberUid: $member" done echo "" done } file=`mktemp -p /vz/root/100/tmp/` basefile=`basename "$file"` dnfile=`mktemp -p /vz/root/100/tmp/` basednfile=`basename "$dnfile"` generate > $file cat $file | egrep "^dn:" | cut -f2 -d' ' > $dnfile vzctl exec 100 ldapdelete -c -x -D "cn=admin,dc=example,dc=com" -w ******** -H ldap://127.0.0.1 -f /tmp/$basednfile vzctl exec 100 ldapadd -c -x -D "cn=admin,dc=example,dc=com" -w ******** -H ldap://127.0.0.1 -f /tmp/$basefile rm -f $file rm -f $dnfile
To create home directories within the new VE the following small script can be used:
#!/bin/bash ldapsearch -x -b "ou=Users,dc=example,dc=com" "objectClass=PosixAccount" "dn" | grep "^dn" | cut -f2 -d' ' | while read dn; do data=`ldapsearch -x -b "$dn"` home=`echo -e "$data" | grep "homeDirectory" | cut -f2 -d' '` uid=`echo -e "$data" | grep "uidNumber" | cut -f2 -d' '` gid=`echo -e "$data" | grep "gidNumber" | cut -f2 -d' '` if echo "$home" | grep "/home/"; then mkdir -p $home chown $uid:$gid $home chmod ug=rwX,o-rwx $home fi done
The last thing that needs to be done is to modify the PAM configuration in the following files.
/etc/pam.d/common-account
account sufficient pam_ldap.so account required pam_unix.so
/etc/pam.d/common-auth
auth sufficient pam_ldap.so auth required pam_unix.so nullok_secure try_first_pass
/etc/pam.d/common-password
password required pam_ldap.so password required pam_unix.so nullok obscure min=4 max=8 md5 use_first_pass
<< Newer entries | Older entries >>