SED Cheatsheet

bash

 

Some useful cheatsheet for sed:-

sed ‘2d’ file.txt Remove second line from file.txt
sed ‘/mickgenie/d’ file.txt Remove the line containing the word/string mickgenie from file.txt
sed ‘$d’ file.txt Remove last line from file.txt
sed ‘/^$/d’ file.txt Remove empty line from file.txt
sed ‘1,5d’ file.txt Remove line between 1 and 5 from file.txt

exim: Check current PHP Script Spam process

exim-logo

 

This post is very useful for those System Administrator or System Engineer who wish to monitor over hundred of servers which could get the spamming PHP script immediately from your server.

The following example was written based on cPanel exim4 and you may stored them in a .sh file.

Continue reading exim: Check current PHP Script Spam process

WordPress migration with SSH

Scenario:
Old Site: www.domain.com/blog
Path: /home/domain/public_html/blog
New Site: www.domain.com (Assume the site is empty)
Path: /home/domain/public_html

In order to move the WordPress account manually without any plugin, you may done it through SSH without any trouble.

Folder/File
1.  Log into the SSH.
2.  Copy the folder and file from blog folder to main site.

cp -apr /home/domain/public_html/blog /home/domain/public_html

3. If you using Permalink and having mod_rewrite rule, you may edit your .htaccess file,

vi /home/domain/public_html/.htaccess

4. Change the rewrite rule from,

RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

to

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Database:
1.  Dump the database. Assume your database named wordpress.

mysqldump wordpress > wordpress.sql

2. Change the entry from www.domain.com/blog to www.domain.com.

sed -i 's/www\.domain.\com\/blog/www\.domain\.com/g' wordpress.sql

3. Restore the database back to the domain.

mysql wordpress < wordpress.sql