WordPress database error MySQL server has gone away for query blah

Edit the php file “wp-db.php” (in the “wp-include/” folder of your WordPress installation) and add

$this->query(“set session wait_timeout=600”);

somewhere in the function “___construct” after the $this->dbhost = $dbhost; and before the $this->dv_connect()
statement.

Reference this link if you need more:

http://dev.mysql.com/doc/refman/5.0/en/gone-away.html

Posted in Linux | Comments Off on WordPress database error MySQL server has gone away for query blah

Delivering root mail locally while relaying others

In order to deliver some accounts locally, you can set up virtual aliases as follows:

1. Add the following line to /etc/postfix/main.cf:
virtual_alias_maps = hash:/etc/postfix/virtual
mail_spool_directory=/var/spool/mail

2. Create /etc/postfix/virtual as follows:
root root@localhost

3. postmap /etc/postfix/virtual

4. Restart postfix

Note: Make sure that /etc/aliases doesn’t have root’s mail being redirected

Posted in Linux | Comments Off on Delivering root mail locally while relaying others

strace

strace -s 512 -f lsyncd -pidfile /etc/lsync.lua

Posted in Linux | Comments Off on strace

Dealing with PEM Keys

# Get the details of a PEM key:
openssl x509 -in <certname>.pem -text

# Check whether a key and cert match using openssl:
openssl rsa -noout -modulus -in server.key | openssl md5
openssl x509 -noout -modulus -in server.crt | openssl md5

Posted in Linux, OPENSSL and TLS | Comments Off on Dealing with PEM Keys

Using blackbox to change multiple dns records for account

browse to https://clouddns.dcx.rackspace.com/zones/search

Enter the account number and click Exact Search

copy the lines from the console to a file called domainlist.txt

domainlist.txt===================

1 View accidentlawyerny.net
2 View acnestories.com
3 View acnewonders.com
4 View aromatherapyrecipe.com
5 View attorneyny.us
6 View attorneynyc.org
7 View bankruptcylawyerny.org
8 View bbbeauty.com

end domainlist.txt===============

browse to https://clouddns.dcx.rackspace.com/scripts/new

click the command you wish to run to get the exact command

for instance edit mx records uses ‘edit_mx_record zone fqdn priority mail_server’

Change the values by running the following command:

perl -pi -e ‘s/^[0-9]+\s+View\s+(.*?)$/edit_mx_record $1 $1 10 mx1.emailsrvr.com/’ domainlist.txt

This will result in a file with the commands to copy into https://clouddns.dcx.rackspace.com/scripts/new. Change the DDI and hit execute, and you should be golden.

Posted in Linux | Comments Off on Using blackbox to change multiple dns records for account

Make fail2ban send emails

Edit /etc/fail2ban/jail.conf as follows:

action = %(action_)s

gets changed to

action = %(action_mw)s

which causes fail2ban to execute an action shortcut that sends mail:

#########section of jail.conf############################################
# Action shortcuts. To be used to define action parameter

# The simplest action to take: ban only
action_ = %(banaction)s[name=%(__name__)s, port=”%(port)s”, protocol=”%(protocol)s”, chain=”%(chain)s”]

# ban & send an e-mail with whois report to the destemail.
action_mw = %(banaction)s[name=%(__name__)s, port=”%(port)s”, protocol=”%(protocol)s”, chain=”%(chain)s”]
%(mta)s-whois[name=%(__name__)s, dest=”%(destemail)s”, protocol=”%(protocol)s”, chain=”%(chain)s”]

# ban & send an e-mail with whois report and relevant log lines
# to the destemail.
action_mwl = %(banaction)s[name=%(__name__)s, port=”%(port)s”, protocol=”%(protocol)s”, chain=”%(chain)s”]
%(mta)s-whois-lines[name=%(__name__)s, dest=”%(destemail)s”, logpath=%(logpath)s, chain=”%(chain)s”]

# Choose default action. To change, just override value of ‘action’ with the
# interpolation to the chosen action shortcut (e.g. action_mw, action_mwl, etc) in jail.local
# globally (section [DEFAULT]) or per specific section
action = %(action_)s

Posted in Linux | Comments Off on Make fail2ban send emails

Changing munin password

To change the serverinfo password for munin,

htpasswd /etc/munin/munin-htpasswd serverinfo

To test, go to http://IP/munin

Posted in Linux | Comments Off on Changing munin password

Adding usb device to qemu in kvm

HOWTO: Use USB devices in Virtual Machine Manager with QEMU

Posted in Linux | Comments Off on Adding usb device to qemu in kvm

Deny POST to a site in .htaccess

 <limit POST OPTIONS>
  Order deny,allow
  Deny from all
 </limit>
Posted in Linux | Comments Off on Deny POST to a site in .htaccess

Useful find Commands

The find command is very verstile, and I use it all the time. Here are the parameters that I use most often:
-name <string> Finds files in specified directory whose name matches (case-sensitive) string
-iname <string> Finds files in specified directory whose name matches (case-insensitive) string
-exec Executes a command on the files found (see ls -l example below)
-perm <mode> Finds files in specified directory that match the permission mode
-size Finds files in specified directory
-print Finds the files and prints out the filename. This is useful in a find . -exec grep
-regex<pattern> Finds files in specified directory with name that matches regular expression pattern.
-atime <+-><n> Finds files in specified directory that were accessed less than, more than, or exactly n minutes ago
-amin <+-><n> Finds files in the specified directory that were accessed less than, more than, or exactly n minutes ago
-mmin <+-><n> Finds files in specified directory that were last modified less than, more than, or exactly n minutes ago
-mtime <+-><n> Finds files in specified directory that were last modified less than, more than, or exactly n*24 hours ago
-type <filetype> Find files in the specified directory of type:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option
or the -follow option is in effect, unless the
symbolic link is broken. If you want to search for
symbolic links when -L is in effect, use -xtype.
s socket

Examples:
Find files in current directory that end in .txt:
find . -name "*.txt"

Find files in current directory that were created within the last hour:
find . -ctime -60

Find 5 largest files
find / -type f -exec ls -la {} + 2>/dev/null | sort -k5 -rn | head -5

Find files in current directory not owned by root:
find . \! -user root -print

Find files in current directory with 0777 permissions and chmod them to 644:
find . -type f -perm 0777 -print -exec chmod 644 {} \;

Find files in current directory with owner apache and change to www-data:
find . -user apache -exec chown www-data {} \;

Find all files in current directory that contain string and output their names:
find . -exec grep string {} \; -print

Find files in the current directory with ACLs set:
find . -type f -exec ls -l {} \; | grep -v "\+"

Find files older than 7 days matching string “vicki_test2 and move to new directory
mkdir -p /var/mitto/data/vicki_dir && find /var/mitto/data/ -regextype posix-extended -regex '^.*vicki_test2.*\.[^.]+$' -mtime +7 -exec mv {} /var/mitto/data/vicki_dir \;


Posted in Linux | Comments Off on Useful find Commands