List Plesk Mail Account
Analyzing Postfix Log Script
MySQL Plesk

How to list databases with their subscription/domain

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

use psa;
select as "Database", as "Subscription",c.pname as "Owner",-
c.login as "Customer Username" from data_bases db,-
domains d,clients c where and INTO OUTFILE '/tmp/dblist.txt';

Highest mysql-connection

mysql -usa -p`cat /etc/.mysql.shadow` -e "show processlist" -
| awk '{print $2}' | sort | uniq -c |sort -k1n | less | tail -n20

Change admin password

Changing the administrator password in Plesk panel does not change,
The [email protected] database password.
In order to update the [email protected] DB user password to NEWPASSWORD:

1) Login to database
# plesk db

2) Run this SQL command:
UPDATE mysql.user SET Password=PASSWORD('BeatlesOther'), plugin='', authentication_string='' WHERE User='admin';

3) Replace the password listed in /etc/psa/.psa.shadow with NEWPASSWORD.
Do not encrypt the new password, just replace the existing line with the new password.

In order to update the administrator password of Plesk panel:
# /usr/local/psa/bin/init_conf -u -passwd NewPassword
Details :
Force redirect to https via .htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.tld/$1 [R,L]
Highest request and concurrent visitor
awk '{ print $1}' <web-server_access_log> | sort | uniq -c | sort -nr | head -n 10
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
Minimize leverage browser (GTMetrix)
#Add this scripts to .htaccess file

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg “access plus 1 year”
ExpiresByType image/jpeg “access plus 1 year”
ExpiresByType image/gif “access plus 1 year”
ExpiresByType image/png “access plus 1 year”
ExpiresByType text/css “access plus 1 month”
ExpiresByType application/pdf “access plus 1 month”
ExpiresByType text/x-javascript “access plus 1 month”
ExpiresByType application/x-shockwave-flash “access plus 1 month”
ExpiresByType image/x-icon “access plus 1 year”
ExpiresDefault “access plus 2 days”
ExpiresByType text/javascript “access plus 1 month”
ExpiresByType text/x-javascript “access plus 1 month”
ExpiresByType application/javascript “access plus 1 month”
ExpiresByType application/x-javascript “access plus 1 month”
Activate Gzip Compression (GTMetrix)
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Generating dummy file of any sizes
fallocate -l 1G dummy.file
dd if=/dev/zero of=dummy.file bs=1G count=1
- if defines the input file
- of defines the output file
- bs defines bytes in a block
- count defines the number of blocks to be copied
- /dev/zero is a character special device, which returns the zero byte (\0).
- Megabyte (1024 KB) = M
- Gigabyte (1024 MB) = G
Find out UUID of interface
uuidgen [interface-name]</br>
uuidgen ifcfg-eth0
Rename all items in cwd to lowercase or uppercase
for i in *; do mv "$i" "${i,,}"; done
for i in *; do mv "$i" "${i^^}"; done
Find out external IP using dig
dig +short
Generate 16 random character for password
tr -dc '[email protected]#$%^&*_()+}{?></";.,[]=-' < /dev/urandom | fold -w 16 | head -n 1
View a file with line numbers
grep -n ^ /path/to/file | less
Looping in one-liners
#Forever with while
while true; do foo; sleep x; done
while true; do curl --head; sleep 1;  done
while true; do nc -z -v 80; sleep 1;  done

#Do action per each line in file
while read LINE; do COMMAND; done < FILE

#For statement
for ((i=0; i<5; i++)); do echo $i done
for i in {a..z}; do echo $i; done
for i in {1..5}; do echo "$i hello, world"; sleep 1; done
for i in /etc/*.conf; do cp $i /backup; done
Check IOPS speed with FIO
#Read, write, read and write
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=random_read_write.fio --iodepth=64 --size=100M --readwrite=randread
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=random_read_write.fio --iodepth=64 --size=100M --readwrite=randwrite
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=random_read_write.fio --iodepth=64 --size=100M --readwrite=randrw
Listing failed login ssh ip-address
lastb | awk '{if ($3 ~ /([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}/)a[$3] = a[$3]+1} END {for (i in a){print i " : " a[i]}}' | sort -nk 3
Querying DNS Record
while true; do for i in `whois domain| grep -i "Name Server" | awk -F ':' '{print $2}'`;do dig @$i domain +short; done; echo "===QUERY RESULT==="; done;
Listing all services on CentOS
systemctl -t service -a 
Bash cheatsheet
Disk perfomance testing
# Sequential Read
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --bs=4k --iodepth=64 --size=4G --readwrite=read
# Sequential Write
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=test.write --bs=4k --iodepth=64 --size=4G --readwrite=write
# Sequential Read Write
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --bs=4k --iodepth=64 --size=4G --readwrite=rw --rwmixread=50
# Random Read
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=test.randread --bs=4k --iodepth=64 --size=4G --readwrite=randread
# Random Write
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=test.randwrite --bs=4k --iodepth=64 --size=4G --readwrite=randwrite
# Random Read Write
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=test.randrw --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=50
Check Common Name of SSL
nmap --script ssl-cert -p 443 domain.tld
Upgrading Ubuntu Version
sudo apt-get update -y
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo do-release-upgrade -y

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrZwU2ZnRd9FqGCQq8SfuHyKZ8DiFMXYVtXZBhwcTU58b+og7XApwJkO5dVy9uvoSkSWyQEC+D1JMuyJIVOambRZgX9/OIzSVl2lG4KBQ/w7ubSkWScMIxuMTiar7S8bTRdb30JYRfX3TnRz1UxalEnuIMaEuuM9yV5kDj0QLC08B51cr4BQe+3ghJQbzcNCZNNYDN463x0tx/WbryIFQQsybcghZWOSrAB7aFKPUJr8GTH1Jz8Fuvlrrg3ChG+SGpDzT1mQ6zrRrB6B53PYVoJa/o/NY1y0mIMSQLdh+7yZBZTRjKqGzV+SCfSDs7Z3zJy2N20GWgn7a77soogU6p [email protected]