Saturday 13 September 2014

vi Find And Replace Text Command


How do I find and replace (substitute) test using vi or vim text editor under UNIX / Linux / BSD or Apple OS X operating systems?


Both vi and vim text editor comes with substitute command for finding and replacing text.


Syntax


The syntax is as follows:
:%s/WORD-To-Find-HERE/Replace-Word-Here/g
OR
:%s/FindMe/ReplaceME/g


Examples


The substitute command can be used as per your requirements.


Task: VI / Vim Basic Find and Replace


To find each occurrence of 'UNIX', and replace it with 'Linux', enter (press ESC, type : and following command):
:%s/UNIX/Linux/g


Task: Find and Replace with Confirmation


Find a word called 'UNIX' and replace with 'Linux', but ask for confirmation first, enter:
:%s/UNIX/Linux/gc


Task: Find and Replace Whole Word Only


Find whole words exactly matching 'UNIX' to 'Linux'; and ask for confirmation too:
:%s/<UNIX>/Linux/gc


Task: Case Insensitive Find and Replace


Find 'UNIX' (match UNIX, unix, UnIx, Unix and so on) and replace with 'Linux':
:%s/unix/Linux/gi
Same command with confirmation:
:%s/unix/Linux/gic


Task: Case sensitive Find and Replace


Find each 'UNIX' and replace with 'bar':
:%s/UNIX/bar/gI
Same command with confirmation:
:%s/UNIX/bar/gIc


How Do I Replace In the Current Line Only?


Find 'UNIX' and replace with 'Linux' in the current line only (note % is removed from substitute command):
:s/UNIX/Linux/g
NOTE: You need to prefix % the substitute command to make changes on all lines:
:%s/UNIX/Linux/g


How Do I Replace All Lines Between line 100 and line 250?


:{START-n},{END-n}s/word1/word2/g
Find 'UNIX' and replace with 'Linux' all lines between line 100 and line 250, enter:
:100,200s/UNIX/Linux/g
OR
:100,200s/UNIX/Linux/gc

ffmpeg installer

Enabling mbstring Library in PHP.ini

cPanel to cPanel migration via SSH - Multiple domains

Know more about localdomains and remotedomains

Services for one domain do not need to be on one server. The site host and email server for a domain do not need to be on the same physical server.


DNS is used to direct the traffic to the correct place, but DNS alone will not get all the bits to where they are supposed to be. Exim, cPanel’s SMTP service needs a little help beyond DNS in order to know how to handle mail that is generated locally.


This is where /etc/localdomains and /etc/remotedomains come into play.





  • How do it works




Email sent out from a cPanel server, exim has to checks /etc/localdomains and /etc/remotedomains in order to send the email to the correct location.


If the domain is in /etc/localdomains, the mail is routed locally to the machine. If the domain is in /etc/remotedomains, the email is routed out to the Internet.


This is useful if the domain has some software installed that sends email notifications, such as a content management system like WordPress. This ensures that mail will get sent to the correct location.


If domain uses a third party mail server for email and the domain is not in remotedomains, notifcations from the CMS will not be delivered.





  • Setting email option during account creation




At the bottom of the account creation page in the Webhost Manager.


If Local Mail Exchanger is set, cPanel places the domain in localdomains. If Remote Mail Exchanger is selected, it places the domain in remotedomains. If Backup Mail Exchanger is selected, the domain will be added to localdomains but will only accept mail if there are no other mail servers available.


Automatically Detect Configuration will check the DNS Mail Exchanger records to see where the DNS is pointed, and make the configuration based off of that. Most of the time, this is the best option to select. However, if DNS has not been setup for the domain yet, you may wish to set the Exchanger manually.


Automatically Detect Configuration will check the DNS Mail Exchanger records to see where the DNS is pointed, and make the configuration based off of that. Most of the time, this is the best option to select. However, if DNS has not been setup for the domain yet, you may wish to set the Exchanger manually.



How to modify my hosts file?

Modifying your hosts file will allow you to override the DNS for a domain, on that particular machine. This can be used to test your site without the test link, prior to going live with SSL, verify an alias site works prior to DNS changes, or for other DNS related reasons. This causes your local machine only to look directly at the IP specified.


Your hosts file will need to have two entries added that will contain the IP address you want the site to resolve to and the address. Adding the below two lines for example will point www.domain.com and domain.com to our current PHP5-ITK ("Refreshed" PHP5) cluster:


1.2.3.4 www.domain.com
1.2.3.4 domain.com


Below is how to locate and edit the hosts file on several OS platforms. Once the proper domain information is added you will save the file and your system will begin resolving to the specified IP. Once testing is finished these entries should be removed.


Contents:-   
Windows Vista and Windows 7
Windows NT/2000/XP
Linux
Mac OSX 10.0 - 10.1.5
Mac OSX 10.6 - 10.8


 


 

Mail queue alert script for cPanel server via email

We need to monitor our server mail queue for cPanel servers, Possible outgoing spam as well as to maintain the server performance. Often large mail queue causes server overloading issues. It is very easy to get an alert if your server mail queue contains more than X  numbers of mails. You can use the following script to monitor your server mail queue for your cPanel servers:




#!/bin/bash
# use: Bash Shell script to monitor or Check Mail queue


EMAIL=”your email address”

MQUEUE=`find /var/spool/exim/input -name ‘*-H’ | wc -l | sed -e “s/ //g”`

if [ $MQUEUE -gt XXX ]; then
echo “Mail queue at `hostname` has $MQUEUE messages!!!” | mail -s “MAIL QUEUE ALERT: Mail queue for `hostname`” $EMAIL
fi