Sunday, August 8, 2010

Ubuntu Firefox 3.6 HtmlValidator extension - Fixed!

Ubuntu 10.04 LTS (Lucid), Firefox 3.6.3, HTMLVALIDATOR extension - howto

1) Download & install HTML Validator extension:
http://users.skynet.be/mgueury/mozilla/download.html

2) Install libstdc++5
http://packages.ubuntu.com/jaunty/i386/libstdc++5/download

3) Link tidy to the library
cd ~/.mozilla/firefox/
find . -name libnstidy.so
#go to that  directory:
cd  directory_of_libnstidy.so
# create symbolic link to libstdc++5
ln -s /usr/lib/libstdc++.so.5 libstdc++.so.5

4) Restart firefox (stop it, wait 10 seconds, start it)

Wednesday, August 4, 2010

Shell parallelization - Shell solution for running same process or different processes in parallel

Multiple instances of same job, in parallel.

Example 1:

#!/bin/bash

secvential-job.sh &
secvential-job.sh &
secvential-job.sh &
secvential-job.sh &
...


Example 2:

#!/bin/bash

secvential-job.sh &
secvential-job.sh &
secvential-job.sh &
secvential-job.sh &
...

# wait for all secvential started processes to finish
wait

# do other stuff ...
email-results.sh


Example 3:

#!/bin/bash

secvential-job1.sh &
secvential-job2.sh &
secvential-job2.sh &
secvential-job3.sh &
...

# wait for all secvential started processes to finish
wait

# do other stuff ...
compute-full-report.sh
email-results.sh

Simple cron locking system

Run cron jobs safely, using locking. Cron lock prevents running a cronjob if the first one didn't finished running (prevents cron overlaps).

2 files are used:
- cron-job1.sh
- cron-job1.lock

Contents of cron-job1.lock will be:
- free - if it's free, cron-job1.sh is NOT running
- locked - if cron-job1.sh is running

Locking script (cron-job1.sh):

#!/bin/bash

lock_file="cron-job1.lock"

lock_content=`cat $lock_file`

if [[ "$lock_content" == "free" ]] ; then

    echo "locked" > $lock_file
  
    # do stuff here:
    cd /some-dir
    php compute-things.php
    php email-results.php

    echo "free" > $lock_file

else
    echo "script already running, file $lock_file is not free"
fi

Tuesday, August 3, 2010

Recursively change directory and file permissions

Recursive php script that updates directories and files permissions.
Directory permissions: 755
File permissions: 644

File update-permissions.php:

ini_set('display_errors', 1);

$dir = '/home/user/folder';

update_perms($dir);

function update_perms($dir, $_dir_perms = '755', $_file_perms = '644') {
    echo "\n" . $dir . '...';
    if(is_dir($dir)) {
        shell_exec("chmod $_dir_perms $dir");
        echo 'dir update';
        $files = scandir($dir);
        unset($files[0]);
        unset($files[1]);
        #print_r($files);exit;
        foreach($files as $file) {
            update_perms($dir . '/' . $file);
        }
    } elseif(is_file($dir)) {
        shell_exec("chmod $_file_perms $dir");
        echo 'file update';
    }
}

Evolutia salariului minim in Romania, 2000 - 2010

Salariul minim in Romania: 600 lei (brut) - ianuarie 2010.
Evolutia salariului minim in perioada 2000 - 2010 si hotararile de guvern care i-au modificat valoarea:
Salariul minim in Romania - istoric 2000 - 2010

Servicii contorizare trafic in Romania, Iulie 2010

Servicii contorizare trafic Iulie 2010
124.757 domenii analizate.
  1. Trafic.ro - 28.380 domenii
  2. Google Analytics - 27.397 domenii
  3. SATI - 395 domenii
Sursa: infodomenii.ro - Servicii contorizare trafic Iulie 2010

Inregistrare domenii – top firme inregistrare domenii

Inregistrare domenii:
- cauti o statistica a firmelor de inregistrare domenii din Romania?
- doresti sa inregistrezi un domeniu nou?
InfoDomenii ofera informatii despre firmele de inregistrare domenii folosite in Romania: firme inregistrare domenii.

SursaDeStiri.ro – toate stirile in acelasi loc

O aplicatie online, cu frecventa de actualizare ridicata, activa 24 de ore din 24: www.sursadestiri.ro. “Sursa de stiri” ofera toate stirile din cele mai importante ziare, intr-un mod unitar, organizate pe categorii. Pentru a fi informat si la curent cu cele mai noi evenimente, foloseste acest site.

Harta publicitatii online din Romania

Un serviciu nou, de calitate: Harta publicitatii online in Romania.
Analize pe seturi mari de date, informatii utile despre agentiile de publicitate din Romania si despre sistemele de contorizare trafic folosite de site-urile romanesti.

Monday, August 2, 2010

Top agentii publicitate in Romania, Decembrie 2009

Top agentii publicitate in Romania, Decembrie 2009

EveryDNS a fost preluat de DynDNS

David Ulevitch, fondatorul EveryDNS (2001), a vandut EveryDNS catre Dyn Inc., care detine DynDNS. EveryDNS administra gratuit aproximativ 400.000 de domenii, domenii care vor trece in administrarea DynDNS. Tranzitia domeniilor se va face fara intreruperea serviciilor. Serviciile vor ramane gratuite in continuare, insa nu se stie pentru cat timp. Sistemul de plata pentru DynDNS momentan constituie in efectuarea unei donatii, in schimbul careia se primeste administrare gratuita life-time pentru acel domeniu.

Client RDS Business – review servicii internet si telefonie

La RDS, orice persoana, fizica sau juridica, poate beneficia de un abonament business. Oferta o primesti pe mail de obicei, dupa ce soliciti acest lucru la relatii cu clientii / dep. comercial, whatever.
Ce primesti in plus:
- portul 25 deblocat – deci poti tine un mail server la tine
- 3 adrese ip statice
- viteza minima garantata
De mentionat ca vitezele maxime sunt mai mici decat la abonamentele fiber link normale, dar sunt garantate.
Si acum despre cum functioneaza aceste servicii:
- daca ai depasit data scadenta a facturii, serviciul e taiat automat; mergi sa platesti si se reactiveaza (tot automat) in max 24 de ore
- in general in caz de avarie a echipamentelor rds (switch, media-convertor), e f. recomandat sa faci o sesizare imediat la Rel. Clienti si problema se rezolva in 24-48 de ore
- in cazuri exceptionale (am patit eu asta), avariile echipamentelor sunt rezolvate intr-un timp f. mare, de 1-2 saptamani; in aceasta situatie, oricate sesizari si reveniri faci, nu se schimba nimic, efectiv oamenii aia nu fac NIMIC; te zbati degeaba. Solutia de urgentare este contacterea unui reprezentant comercial (cel cu care ai semnat contractul) si amenintarea cu rezilierea, etc. In toate interactiunile cu angajatii RDS este f. recomandat sa fii f. ager si pe faza, ei au un talent deosebit de a se eschiva si de a te duce cu vorba pentru a scapa de tine.
- daca nu functioneaza internetul timp de 2 saptamani sa zicem, tot nu esti indreptatit conform contractului sa renunti la serviciile lor. In contract se precizeaza ceva de genul ca timp de 3 luni daca nu functioneaza internetul mai mult de 30 zile, abia atunci, tu, clientul, poti renunta la serviciile lor. De asemenea, daca vrei reziliere, trebuie sa notifici cu 60 de zile inainte acest lucru.
Pe scurt, RCS-RDS, este o firma care ofera servicii de internet f. bune la nivel de tara/orase si efectiv are cea mai buna oferta de net. Si ieftin si f. bun!! DAR, DE RETINUT, nu se merita sa faci un abonament business la ei. Pur si simplu nu-ti garanteaza up-time-ul necesar si se poarta total neprofesionist…
Pentru net pentru acasa, sunt f. ok, insa daca vrei mai mult, sa faci un hosting, sa tii niste servere, si te gandesti la un abonament business la RDS, nu e alegerea cea mai fericita.
Am patit-o cu ei si efectiv “mi-au mancat sanatatea”. Am sunat de mi-a venit rau la ei… pe banii mei, normal…
Si inca o faza “clasica”: cand depui o sesizare, intrebarea clasica a operatorului “dobitoc” este: “cand sunteti in locatie pentru a trimite o echipa pe teren?”. Si tu-i zici: “bai, inteligentule, defectiunea e pe scara, am precizat asta de la inceput, de ce trebuie eu sa fiu in locatie?”. Iar, el, vadit surprins de acest raspuns, revine cu aceeasi intrebare: “cand sunteti in locatie pentru ca trebuie sa completez aici formularul”. Deci, … ma abtin… astia sunt oamenii de acolo.

Mysql export SQL Server compatible

Export Mysql – SQL Server:
mysqldump --compatible=mssql dbname > dump.sql

Ubuntu O2 prepaid internet stick – Ubuntu 10.04 LTS

Ubuntu 10.04 LTS O2 Qualcomm 3G icon howto.
O2 prepaid internet stick.

Install usb_modeswitch and comgt (comgt is necessary if the stick has a sim with PIN code)
sudo apt-get install usb-modeswitch comgt

Create new file
sudo mcedit /etc/usb_modeswitch.d/1e0e\:f000
with content:
#-----------------------
# Option iCON 210
#
#
# Contributor: wahlm
#
DefaultVendor= 0x1e0e
DefaultProduct= 0xf000

TargetVendor= 0x1e0e
TargetProduct= 0x9000
TargetClass= 0xff

MessageEndpoint=0x1
MessageContent="55534243689d528100000000000006bd000000020000000000000000000000"

ResponseEndpoint=0x1
#------------------------------

Insert the stick

Check device id
lsusb

Create new ppp connection (Choose CHAP authentication, name it o2-prepaid)
sudo pppconfig

Create connect script (./o2-prepaid-stick-connect):
#!/bin/bash
sudo usb_modeswitch -c /etc/usb_modeswitch.d/1e0e\:f000
sudo modprobe usbserial vendor=0x1e0e product=0x9000
sudo comgt -d /dev/ttyUSB2
sudo pon o2-prepaid


Run script:
$ sudo ./o2-prepaid-stick-connect
Looking for target devices ...
Found devices in target mode or class (1)
Looking for default devices ...
No default device found. Is it connected? Bye.

Enter PIN number: ****
Waiting for Registration..(120 sec max).
Registered on Home network: "o2 - de",2
Signal Quality: 15,99
Done! It works!

Backup linux server - Rsync Backup - solutie backup

Solutie de backup folosind rsync. Rsync backup tutorial complet.
Avem 2 masini: client, server. Pe client dorim sa avem o copie fidela a unor directoare de pe server.
Este necesar sa fie deschise in paralel 2 shell-uri pe ambele masini, pentru a rula comenzile intercalat.
In comenzile de mai jos cuvintele “server” si “client” se pot inlocui cu numele masinilor pentru o utilizare mai usoara.
client:
su -
cd /root
mkdir rsync-server
cd rsync-server
ssh-keygen -t dsa -b 1024 -f rsync-server-key

server:
su -
cd /home
mkdir rsyncclient
useradd -d /home/rsyncclient rsyncclient
chown -R rsyncclient rsyncclient


client:
# — copiem rsync-server-key.pub pe server (securizat, folosind scp):
scp rsync-server-key.pub root@server:/root/
server:
mv /root/rsync-server-key.pub /home/rsyncclient
cd /home/rsyncclient
mkdir .ssh
chmod 700 .ssh
mv rsync-server-key.pub .ssh/
cd .ssh
touch authorized_keys
chmod 600 authorized_keys
cat rsync-server-key.pub >> authorized_keys
cd ..
mcedit validate-rsync

#!/bin/sh
case "$SSH_ORIGINAL_COMMAND" in
*\&*)
echo "Rejected"
;;
*\(*)
echo "Rejected"
;;
*\{*)
echo "Rejected"
;;
*\;*)
echo "Rejected"
;;
*\<*)
echo "Rejected"
;;
*\`*)
echo "Rejected"
;;
*\|*)
echo "Rejected"
;;
rsync\ --server*)
$SSH_ORIGINAL_COMMAND
;;
*)
echo "Rejected"
;;
esac
chmod +x validate-rsync
chmod 700 validate-rsync

# — validate-rsync permite doar rularea comenzilor rsync pentru sesiunea deschisa de pe client
chown -R rsyncclient /home/rsyncclient
mcedit .ssh/authorized_keys

# — adaugam ca prefix ip-ul clientului, pentru a permite conexiuni doar de pe client:
from="ip_client",command="/home/rsyncclient/validate-rsync" ssh-dss ....
client:
# — Comanda de backup:
rsync -az -e "ssh -i /root/rsync-server/rsync-server-key" rsyncclient@server:/DIRECTORY_TO_BACKUP /BACKUP-STORE-CLIENT/

Cron: disable mail sending

Cron keeps sending messages and a huge list forms.
In order to disable cron sending mail messages:
edit /etc/crontab and add or modify: MAILTO=""

Export useri si privilegii mysql

Trebuie exportate inregistrarile care ne intereseaza din db mysql, tabelele: user, tables_priv, db.
Query-urile rezultate (insert) se ruleaza pe serverul destinatie. Apoi, FLUSH PRIVILEGES.

Dump multiple databases from console - mysqldump

mysqldump -u root -p --create-options --databases dbname1 dbname2 > dbs.sql
Use --create-options to have “create database” statements. Do not use this option if databases already exists.
Simply dump all databases:
mysqldump -u root -p --create-options -A > dbs.sql
Import them:
mysql -u root -p < dbs.sql

Ubuntu 10.04 LTS – install from usb stick - windows tutorial

Howto install Ubuntu 10.04 LTS from usb stick.
Create usb stick image from Windows:
1) Get Ubuntu Ubuntu 10.04 LTS
2) Download UNetbootin
3) Run UNetbootin and select source (ubuntu image) and destination (usb drive)
4) Restart and boot from usb

Perl, Cpan Install Google Page Rank

install:
cpan
install WWW::Google::PageRank
install LWP::UserAgent
install URI::Escape

gpr2.pl file content:
#!/usr/bin/perl
use WWW::Google::PageRank;
my $domain = $ARGV[0];
my $pr = WWW::Google::PageRank->new;
print "PR: ", scalar($pr->get("http://$domain")), "\n";

usage:
./gpr2.pl domain_name

Defragmentarea pe linux nu este necesara

Procesul de defragmentare, atat de necesar pe windows, nu are nici o aplicabilitate pe linux datorita modului in care sistemul de fisiere de pe linux functioneaza. Pe windows, sistemul de fisiere stocheaza informatiile secvential pe hard-disk. In cazul in care un fisier este editat si isi mareste dimensiunea, spre exemplu, dupa editare, informatia nou adugata este stocata pe hard-disk intr-o locatie diferita. Astfel, fisierul este fragmentat. Pe linux, sistemul de fisiere este diferit, continutul fisierelor fiind stocat unitar (nefragmentat) in zone diferite ale hard-diskului.

windows
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
000|CONTINUTFISIER1||CONTINUTFISIER2||CONTINUTFISIER3|000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000

linux
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
0000|CONTINUTFISIER1|000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000|CONTINUTFISIER2|000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000|CONTINUTFISIER3|0000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000

Din reprezentarile de mai sus se poate observa cu usurinta – chiar si in situatia in care mai este suficient de mult spatiu liber pe hard-disk – ca fragmentarea fisierelor are o rata de aparitie mult mai mare in cazul windows (exemplu: modificare dimensiune fisier in urma editarii).
Presupunem ca editam fisierul 1, adaugand mai multe informatii in el. Rezulta:
windows
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
000|CONTINUTFISIER1_PART1||CONTINUTFISIER2||CONTINUTFISIER3||CONTINUT
FISIER1_PART2|0000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000

linux
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
0000|CONTINUTFISIER1_EDITAT|00000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000|CONTINUTFISIER2|000000000000000
000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000|CONTINUTFISIER3|0000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000

Windows – fisier 1 = fragmentat
Linux – fisier 2 = nefragmentat
Pentru a continua aprofundarea subiectului:
http://geekblog.oneandoneis2.org/index.php/2008/11/13/fighting-fragmentation-on-linux

Monitorizare server linux - Munin

Munin – solutie monitorizare server linux, setup f.f. rapid, rapoarte generate in cateva minute. Db-ul folosit e rdd, nimic de setat in plus, e f.f. rapid.
Install & Setup (debian)
su -
apt-get install munin munin-node
mcedit /etc/munin/munin.conf (update htmldir /var/www/...web_path.../munin)
mkdir /var/www/...web_path.../munin
chown munin:munin /var/www/...web_path.../munin
/etc/init.d/munin-node restart

Extra
Protect: /var/www/…web_path…/munin
mcedit /var/www/...web_path.../munin/.htaccess
AuthType Basic
AuthName "Members Only"
AuthUserFile /var/www/www.example.com/.htpasswd
require valid-user
htpasswd -c /var/www/...web_path.../munin/.htpasswd munin-admin-user

Edit apache.conf .. create new virtual host, etc

Change bash color - Schimbat culoare bash

edit ~/.bashrc
export PS1=’\e[0;31m[\u@\h:\w]\$ ‘
* Black 0;30
* Dark Gray 1;30
* Blue 0;34
* Light Blue 1;34
* Green 0;32
* Light Green 1;32
* Cyan 0;36
* Light Cyan 1;36
* Red 0;31
* Light Red 1;31
* Purple 0;35
* Light Purple 1;35
* Brown 0;33
* Yellow 1;33
* Light Gray 0;37
* White 1;37

Linux remote desktop command / tool

rdesktop 192.168.103.174
rdesktop 192.168.101.154
rdesktop 192.168.102.124

Mount from network, using sshfs

sudo apt-get install fuse-utils sshfs
sudo modprobe fuse
sshfs -o uid=`id -u`,gid=`id -g`,idmap=user,nonempty,workaround=rename user@host:/home/user/files /mnt/remote_files_mounted_here