Saturday, 15 March 2014

Script to create a directory with current date and sync the folders

Script to create a directory with current date and sync the folders

#!/bin/bash
# rsync script
mkdir /home/user/backup/`date -I`
rsync -avz --progress /home/user/rsync1/ /home/user/backup/`date -I`

Find & Replace across multiple files in linux


Command to Find & Replace a word with another across multiple files in linux

>>> command to replace "test" with "testing" in multiple files

# find . -name "*.html" -print | xargs sed -i 's/test/testing/g'

Script to delete mail on a specific time period

Script to delete all mails dated 2011 from the mail accounts. email account: user@example.com


=====================
1) touch --date "2011-06-19" /home/example/mail/example.com/user/cur/start  
         >>> creating a file with particular date [from that date onwards] that we want to delete

2) touch --date "2011-12-31"/home/example/mail/example.com/user/cur/end
        >>> file created with a particular date [upto that date] that we want to delete

3) find . -newer /home/example/mail/example.com/user/cur/start -not -newer /home/example/mail/example.com/user/cur/end -exec mv {} --target-directory=/home/example/mov_mail/ ';'
       >>> script will move mails dated from 2011-06-19 to 2011-12-31 to the folder /home/example/mov_mail/

4) deleted the contents in the folder /home/example/mov_mail/

Remove IP from drop list in iptables

List existing chains

Type the following command to list current IPs in tables:
iptables -L -n

To display line number along with other information, enter:
iptables -L INPUT -n --line-numbers

You will get the list of all blocked IP. Look at the number on the left, then use number to delete it. For example delete line number 10 (subner 134.175.0.0/16), enter:
iptables -D INPUT 10

======================================================

Run :
iptables-save| grep xx.xx.xx.xx

to get the exact rule command used to enabled the block. It will be something like:

-A INPUT ! -i lo -s xx.xx.xx.xx -j DROP

Take this command, replace the -A with -D and run it through iptables:

iptables -D INPUT ! -i lo -s xx.xx.xx.xx -j DROP 

Plesk mx record change

To change an MX, A or CNAME record do the following:
    Log into Plesk
    Click on Domains
    Click on the domain name in question
    Click on the arrow next to the words "Web Site" and choose DNS Settings


To change an MX record:
    Click on the MX record to edit
     Leave "Record type" as MX
     Leave "Enter mail domain" blank
     Change the "Enter mail exchanger" to the name of your mail server
     If necessary, change the "Specify priority of mail exchange server" to the desired setting.

=============================================

To get to the DNS editor, do the following:
    Log into Plesk
    Under Hosting Services, click on Domains
    Find the domain in question, and click on the corresponding link that says "Control Panel" (on the far right side)
    Click the "Websites & Domains" tab
    Click the "DNS Settings" link
    Click on "[Manage]" for the appropriate domain
     To edit an existing record, click on the record under "Host"

MX records
     Change the "Record type" to MX (if necessary)
     "Mail domain" should be left blank
      Set the "Mail exchange server" the name of your mail server (for example ghs.google.com)
      The party who gave you the mail exchange server name may have also given you a priority number; if   not, "very high(0)" is perfect

After making your changes, click on OK. The changes will take between 4 to 8 hours to update worldwide.

     

To find symbolic link in a directory

to find symbolic link in a directory

 root@server [/home/user]# find . -type l
./access-logs
./www

root@server [/home/user]# find . -type l -printf " %p -> %l\n"
 ./access-logs -> /usr/local/apache/domlogs/user
 ./www -> public_html

root@server [/home/edennatu]# find . -type l -printf "%a -> %b\n"
Mon Jun 10 07:41:11 2013 -> 0
Mon Jun 10 07:41:11 2013 -> 0


%a       File's last access time in the format returned by the C 'ctime' function.

%b       The amount of disk space used for this file in 512-byte blocks. Since disk space is allocated in      multiples of the filesystem block size this is usually greater than %s/1024, but it can also be smaller if the file    is a sparse file.

%p       File's name.

%l         Object of symbolic link (empty string if file is not a symbolic link).

Handle spamming in qmail

Qmail Commands:

root@linux ~]# /var/qmail/bin/qmail-qstat 
messages in queue: 123 
messages in queue but not yet preprocessed: 0 

You can examine the queue with qmail-qread. 

/var/qmail/bin/qmail-qread

From the qread command you get the message’s id . If the id is 12345 .
Now you can find the file holding the email in/var/qmail/queue with “find “command.

find /var/qmail/queue -iname 12345

Above will output like this :
/var/qmail/queue/remote/22/12345 
/var/qmail/queue/mess/22/12345 
/var/qmail/queue/info/22/12345 

Now open that file and you should be able to get the details.

vi /var/qmail/queue/mess/22/12345

If you wish to completely remove all the mails from queue just run the below commands.

find /var/qmail/queue/mess -type f -exec rm {} \;
 find /var/qmail/queue/info -type f -exec rm {} \; 
find /var/qmail/queue/local -type f -exec rm {} \; 
find /var/qmail/queue/intd -type f -exec rm {} \; 
find /var/qmail/queue/todo -type f -exec rm {} \; 
find /var/qmail/queue/remote -type f -exec rm {} \;