Tikejhya: Ashish Nepal


Month: August 2011 (Page 2 of 4)

Script: Dump MySQL

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Below Given mysql_dump script, gives general idea to dump database rotate within the given folder and clear data from database.


export DB_BACKUP="/home/tikejhya/mysqldump"

echo ""
echo "mySQL_backup"
echo "----------------------"
echo "* Rotating backups..."
rm -rf $DB_BACKUP/04
mkdir $DB_BACKUP/01

echo "* Creating new backup..."
mysqldump Database > $DB_BACKUP/01/Database -`date +%Y-%m-%d`
echo "----------------------"
echo "Backup Done"
echo "----------------------"
echo "* Clearing backed-Up data*"
mysql -Bse 'DELETE FROM tablename WHERE fieldname < CURDATE()- 5' Database ;
echo "Database Cleared";
exit 0

Enable cronjob, so that it automatically does this job everyday,
Meaning: You are backing up data everyday, only reason -5 is to ensure we dont delete all data.

crontab -e

@daily /path/to/the/script.sh

-B, --batch Don't use history file. Disable interactive behavior. starts with this option ENABLED by default! Disable with

-s, --silent Be more silent. Print results with a tab as separator, Buffer for TCP/IP and socket communication

-e, --execute=name Execute command and quit. (Disables --force and history file)

How can I check my hard disk usage in Linux?

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

# df -h

Check Processor

cat /proc/cpuinfo

Mysqldump with auto rotate [script]

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.


# modify the following to suit your environment
export DB_BACKUP="/backup/mysql_backup"
export DB_USER="root"
export DB_PASSWD="********"

# title and version
echo ""
echo "mySQL_backup"
echo "----------------------"
echo "* Rotating backups..."
rm -rf $DB_BACKUP/04
mkdir $DB_BACKUP/01

echo "* Creating new backup..."
mysqldump --user=$DB_USER --password=$DB_PASSWD --all-databases | bzip2 > $DB_BACKUP/01/mysql-`date +%Y-%m-%d`.bz2
echo "----------------------"
echo "Done"
exit 0

Security Solutions

user and password is to create a file called “.my.cnf” in the user’s home.
The file’s contents should look like this :


backup script delete the user and pass parameteres, because mysqldump (and all mysql command)
looks for a .my.cnf file in the user’s home and takes the login information from there.

I hope you will find this useful.

Run selenium-server-version.jar file On Startup (Linux)

vi /usr/local/bin/selenium.server.sh




JAVA=/usr/bin/java # full path of java which can be seen by doing which java

SELENIUMSERVER=/full/path/to/seleniumserver.jar # full path to the file you looking to run on startup

USER=(username goes here) #normally run this command under for username

/bin/su – $USER -c “$JAVA -jar $SELENIUMSERVER &”

make it executable with the command:

chmod 755 /usr/local/bin/selenium.server.sh

As root … run this command:


Then you should be able to do:

netstat -tupan | grep java
ps -ef | grep java
you will see something if it works then. 🙂

add below given line /usr/local/bin/selenium.server.sh at the bottom of /etc/rc.d/rc.local

Selenium Server (includes: Centos, Java, Rubygem )

Hi, please cross check selenium office website for other language and detailed description.

This would be sufficient for those who are using, Centos, and Ruby.

Install the Selenium RC Server.
Set up a programming project using a language specific client driver.

Installing Selenium Server
Download: Latest: http://seleniumhq.org/download/

java -jar selenium-server-standalone-.jar

Check Java if Installed otherwise, “yum install java”

java -version
If you get a version number (which needs to be 1.5 or later),

Ready Seady Go.

Check ports if its running: (Default)
ngrep -l -q -d eth0 tcp and port 4444
If not running
java -jar selenium-server-standalone-2.4.0.jar
If no ngrep command found.
yum install ngrep

Once setup is done,

Testing from any client PC with PHPUnit,

Read More

Check Database Size (Mysql, CentOS)

If you want to check the size of the databases available in ur msyql, Paste the below given query.

SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;

All size and all tables..

SELECT concat(table_schema,'.',table_name),
concat(round(table_rows/1000000,2),'M') rows,
concat(round(data_length/(1024*1024*1024),2),'G') DATA,
concat(round(index_length/(1024*1024*1024),2),'G') idx,
concat(round((data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(index_length/data_length,2) idxfrac
FROM information_schema.TABLES
ORDER BY data_length+index_length DESC LIMIT 20;

ngrep (network traffic analyzer)

ngrep -l -q -d eth0 tcp and port 10514

Capture network traffic incoming to eth0 interface and show parameters following HTTP GET or POST methods

ngrep -l -q -d eth0 “^GET |^POST ” tcp and port 80

# Capture network traffic incoming to eth0 interface and show the HTTP User-Agent string

ngrep -l -q -d eth0 “User-Agent: ” tcp and port 80


ngrep -itq -W byline src

Move and upgrade Redmine

There were three main things that must be copied over:
The Subversion repository
The Redmine database
the Redmine uploaded

Copy over the latest Redmine database,
Redmine files and
Subversion from the old dev box:

sudo svnadmin dump svn/repository > /tmp/svn_repository.dmp
gzip /tmp/svn_repository.dmp
tar czf /tmp/redmine_files.tar.gz -P /var/www/apps/redmine
mysqldump -uredmine redmine > /tmp/redmine_backup.sql
gzip /tmp/redmine_backup.sql
cd /tmp
scp svn_repository.dmp.gz redmine_backup.sql.gz redmine_files.tar.gz workbooks@

Back on the new dev box, drop and recreate the redmine database:

mysql -uroot -p
drop database redmine;
create database redmine character set utf8;
grant all privileges on redmine.* to ‘redmine’@’localhost’;

Restore the Redmine database:

gunzip redmine_backup.sql.gz
mysql -uredmine redmine < redmine_backup.sql Restore the Redmine file attachments and set permissions: tar xzf redmine_files.tar.gz sudo chown -R www-data:www-data /var/www/apps/redmine/* Restore the SVN repository: gunzip svn_repository.dmp.gz sudo mv /var/svn/repository /var/svn/repository.test sudo svnadmin create /var/svn/repository sudo svnadmin load /var/svn/repository < svn_repository.dmp DO not forgot the file attachments - they aren't stored in Redmine's database - they are in the redmine application directory on the filesystem. (rake upgrade of the database structure) http://www.redmine.org/projects/redmine/wiki/RedmineUpgrade

Rsyslog installation in Centos (Encryption, Monitoring and Mysql)

#yum install rsyslog rsyslog-mysql mysql-server php php-mysql php-gd httpd mod_ssl

download From here to accept tls support on rsyslog http://www.rsyslog.com/download/
If i am not wrong rsyslog lower version doesnot support TLS encryption.

#chkconfig –levels 345 rsyslog on
#chkconfig –levels 345 httpd on
#chkconfig –levels 345 mysqld on
#service syslog stop
#chkconfig –del syslog

rSyslog uses the same syntax as syslog.conf.
copy syslog.conf over rsyslog.conf

To rSyslog have access to MySQL it’s necessary to load the ommysql plugin, add this line at the begin of the /etc/rsyslog.conf file.
$ModLoad ommysql.so

please find below all client and server configuration

Creating a MySQL database for rSyslog
Before everything, it’s needed to start MySQL service
service mysqld start

As root, lets create the access for the user from rSyslog to connect do database
mysql> CREATE USER ‘rsyslog’@’localhost’ IDENTIFIED BY ‘password’;
mysql> GRANT ALL PRIVILEGES ON rsyslog.* TO ‘rsyslog’@’localhost’ WITH GRANT OPTION;

Now, create the database that will be used by rSyslog

As root, run
mysql < /usr/share/doc/rsyslog-mysql-2.0.6/createDB.sql Note: Version of rsyslog-mysql-may be different. Back to the file, /etc/rsyslog.conf add this line before the rsyslog directives
*.* :ommysql:localhost,Syslog,rsyslog,P45sword

At the end of this process, the file /etc/rsyslog.conf will look like
$ModLoad ommysql.so

*.* :ommysql:localhost,Syslog,rsyslog,P45sword

*.info;mail.none;authpriv.none;cron.none /var/log/messages
authpriv.* /var/log/secure
mail.* -/var/log/maillog
cron.* /var/log/cron
*.emerg *
uucp,news.crit /var/log/spooler
local7.* /var/log/boot.log

Allowing remote connections to rSyslog

Edit the /etc/sysconfig/rsyslog file and add the parameter -r at line 6

It’s possible to start rsyslog right now, so you can see if everything gonna ok
service rsyslog start

Installing the Web UI client for rSyslog

With the rsyslog service ok, comes the part where we configure the web interface to make de filters, queries etc.

Download the frontend Log Analyzerto your server
wget http://download.adiscon.com/loganalyzer/loganalyzer-3.2.1.tar.gz
(Check for the latest Version @ http://loganalyzer.adiscon.com/downloads )

Extract to /usr/src

Go to directory where you extracted it, in this case /usr/src/loganalyzer-3.2.1 and copy the directory src to /var/www/html
cp -R src /var/www/html/syslog
cd /var/www/html/syslog
touch config.php
chown apache config.php

If you haven’t started apache yet, you can do it now
service httpd start


Note the error, it’s normal and awaited. Click in “here” to start configuring LogAnalayzer

The installer will check the OS for the prerequisites to start the program. Click “Next”.

The test was done on the phpLogCon has write access to config.php file that we created and defined the permission. Click “Next” to continue.

On Basic Configuration, let the default options selected. Click “Next”.

This is the most important part, it’s here that will be configured the data sources from Syslog.

Change the field “Source Type” to “MySQL” and fill the fields on block “Database Type Options”, like the figure above.

Click Next.


Click “Finish!” and you will be redirected to the main screen for the phpLogCon.

Setting clients to log on Syslog server

On Linux clientes that you wanna log on a Syslog server, you must configure /etc/syslog.conf and add the following line:

*.* @here goes server ip or hostname

With this done, you need to restart Syslog service on host client
service syslog restart

Making rsyslog of server usageble by PHP, APACHE or any other application,

How to parse local files into mysql database.
Inside virtualhost, please sue this instead of own customLog or ErrorLog

ErrorLog “|/usr/bin/logger -p local2.info”
CustomLog “|/usr/bin/logger -p local1.info” combined

Getting TLS (passing Encrypted traffic from client machine to remote server.)

encrypt with TLS – Security.

Read More

Exiting Vi and going back

Suspend VI


Get back to your shell


start a subshell using:


(as configured by)

:set shell?



Page 2 of 4

Powered by WordPress & Theme by Anders Norén