Monday, 27 December 2010

Upgrade Ubuntu server

aptitude update
and install the package update-manager-core:
aptitude install update-manager-core


Then run

do-release-upgrade

More details in howtoforge

Friday, 24 December 2010

'add-apt-repository: command not found'

add-apt-repository isn't installed by default. You have to install the python-software-properties package first.

sudo apt-get install python-software-properties

Thursday, 9 December 2010

Install Postgresql 8.4 on Ubuntu 10.10

Install postgres and the python libraries:
sudo apt-get install postgresql-8.4 postgresql-client-8.4 python-psycopg2
Modify the config file to allow local connections:
sudo nano /etc/postgresql/8.4/main/pg_hba.conf
Add the line:
local     all         all     md5
Save the changes to the file and restart the server.
sudo /etc/init.d/postgresql restart
Set the password for the postgres user:
sudo passwd postgres
Change to the postgres user:
su - postgres
Create a new Database:
createdb mydb
Login to the postgres shell and point to our new database:
psql mydb
Now from the postgress shell create a user and give him access to the database:
mydb=> CREATE USER myuser WITH PASSWORD 'myPassword';
mydb=> GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
mydb=\q
Done!

Source:  Videntity's Blog


Sunday, 5 December 2010

batch rename in Linux command line

The most intuitive way is  'sed' a loop. like this


for file in *.*; do mv $file `echo $file | sed 's/foo/bar/g'` ; done;
-----





Friday, 3 December 2010

DDoS blocker script

First off, try this handy command to check connected IPs:

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n


(D)DoS Deflate is a lightweight bash shell script designed to assist in the process of blocking a denial of service attack. With (D)DoS Deflate you can configure how long will the IP address will be blocked and how many connection considered as DDoS.

How to install it:
1. Open your terminal and login as root
2. Download (D)DoS Deflate:

wget http://www.inetbase.com/scripts/ddos/install.sh

3. Give execute permission to the script:

chmod 0700 install.sh

4. Install it:

./install.sh

To add your ip address as whitelist, edit this file:

nano /usr/local/ddos/ignore.ip.list

Configure (D)DoS Deflate:

nano /usr/local/ddos/ddos.conf

More details at (D)Dos Deflate


-------------------REMOVING IPTABLES RULES-------------------
With command line :

iptables -L INPUT -n --line-numbers

You'll get the list of all blocked IP. Look at the number on the left, then :

iptables -D INPUT ((line number here))

Unix command to analize access.log

The first column is number of connection attempts.

cat access.log | awk '{print $1}' | sort | uniq -c | sort -n

Tuesday, 16 November 2010

How to backup/restore site and mysql database

Frequently you would need to back up and restore site's files and database

-To backup drupal files, better to compress them first so go to the root:

tar -cvjf site.tar.bz2 /path/to/site

- To decompress the above:

tar -xjvf site.tar.bz2

- To backup mysql database ('username' is Mysql username)

mysqldump -u username -p databasename > /path/to/dumpfile.sql

- Also it is better to compress the database if you need to download it:
tar -xjvf dumpfile.sql.tar.bz2 /path/to/dumpfile.sql

- To restore a backed up mysql databas (after decompressing it)

mysql -u username -p databasename < /path/to/dumpfile.sql

Monday, 25 October 2010

Set up virtualenv and start a django project

This has been a headacke for me. At last I figured out that the best practice is to set up projcets through a virtualenv. So let's first install it

easy_install virtualenv


Afterwards, you must decide where you want to store your virtual environments, Then, we will create our actual new virtual environment.

mkdir ~/djenv
virtualenv ~/djenv/env1

Then you need to activate the environment:

source ~/djenv/env1/bin/activate

You should see '(env1)' comes at the left of the terminal.

So now you can install Django in this environment:

pip install Django


Set up django project wherever you like, e.g.:

mkdir -p ~/sites
cd ~/sites
django-admin.py startproject proj1


To get out of the environment:

deactivate env1


That's it. enjoy!

For mor info...

Friday, 22 October 2010

Split video file using ffmpeg and mencoder

Example:

ffmpeg -i input.flv -ss hh:mm:ss -t hh:mm:ss output.flv

Where:

-ss :  Buration
-t : Start time
hh: hours
mm: minutes
ss: seconds

If this does not work try mencoder:

 mencoder -ss 00:00:00 -endpos 00:35:20 -oac pcm  -ovc copy input.mp4 -o output.mp4

Wednesday, 20 October 2010

script to set drupal permissions

#! /bin/bash
cd /var/www/drupal
chown -R drupmin:www-data .
find . -type d -exec chmod u=rwx,g=rx,o= {} \;
find . -type f -exec chmod u=rw,g=r,o= {} \;

cd sites
find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
find . -name files -type d -exec find '{}' -type f \; | while read FILE; do chm$
find . -name files -type d -exec find '{}' -type d \; | while read DIR; do chmo$


echo "Permission rebuildng is done!"