View all incoming HTTP requests More

Viewing incoming HTTP requests can be using for finding a high amount of requests going to a certain domain on your server.

To view all HTTP GET requests, run the following command as root:

tcpdump -s 0 -A \'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420\'

For HTTP POST requests run the following:

tcpdump -s 0 -A \'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504f5354\'

Delete files before certain date More

If you have a directory with a large amount of file, you may want to delete all files before a certain date.

With the below example, we can delete all files before 2016-01-01 00:00.

touch -t 201601010000 /tmp/timestamp

find . -type f ! -newer /tmp/timestamp -delete

Formatting a cron job More

Format for cron jobs

mi h d m w command

Examples:

Run at ten minutes past the hour, every hour, day etc.

10 * * * * ls

Run every five minutes, on the 6th hour, every day etc.

*/5 6 * * * ls

Run on the 14th, 29th, 44th and 59th minute of every hour etc.

14,29,44,59 * * * * ls

Postfix remove emails from mail queue More

Remove all emails in queue

postsuper -d ALL

Remove all emails relating to email address

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } /email\[email protected]\.com/ { print $1 }' | tr -d '*!' | postsuper -d -

Silencing a cron job More

Append >/dev/null 2>&1 to a cron job to silence all output.

The following example sends STDOUT (1) and STDERR (2) to /dev/null, effectively silencing all output.

0          0   *  *  *    /bin/bash /opt/somescript.sh >/dev/null 2>&1

Monitor what is accessing/modifying a fi... More

To watch a file for changes, you can do this with auditctl with the following command:

auditctl -w /path/to/filename -p wa

All changes will then be shown in the audit log (/var/log/audit/audit.log)

tail -f /var/log/audit/audit.log

Once you have found what you\'re looking for, remove the watch with the following:

auditctl -W /path/to/filename -p wa

Upgrade MySQL using MySQL Community Repo... More

Find the correct release RPM for your version of CentOS from the MySQL Download Page (https://dev.mysql.com/downloads/repo/yum/)

cat /etc/redhat-release

  CentOS release 6.8 (Final)

wget https://dev.mysql.com/get/mysql57-community-release-el6-9.noarch.rpm

yum localinstall mysql57-community-release-el6-9.noarch.rpm

 

Edit the following file and enable the version of MySQL that you want to upgrade to. Also ensure you disable the ones you don\'t want.

 

vim /etc/yum.repos.d/mysql-community.repo

 

yum update mysql-server

 

mysql_upgrade

 If you\'re using Plesk, you will need to run mysql_upgrade with the following parameters:

mysql_upgrade -uadmin -p`cat /etc/psa/.psa.shadow`