List Plesk Mail Account
 /usr/local/psa/admin/bin/mail_auth_view
Analyzing Postfix Log Script
http://adminlogs.info/2012/07/22/how-to-get-mail-statistics-from-your-postfix-mail-logs/
MySQL Plesk

How to list databases with their subscription/domain

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

use psa;
select db.name as "Database",d.name as "Subscription",c.pname as "Owner",-
c.login as "Customer Username" from data_bases db,-
domains d,clients c where d.cl_id=c.id and db.dom_id=d.id 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.
Details: https://support.plesk.com/hc/en-us/articles/213364309

In order to update the administrator password of Plesk panel:
# /usr/local/psa/bin/init_conf -u -passwd NewPassword
Details : https://support.plesk.com/hc/en-us/...-or-reset-password-for-admin-account-in-Plesk
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

## EXPIRES CACHING ##
<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”
</IfModule>
## EXPIRES CACHING ##
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/vnd.ms-fontobject
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 myip.opendns.com @resolver1.opendns.com
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 https://darin.web.id; sleep 1;  done
while true; do nc -z -v darin.web.id 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
https://devhints.io/bash
https://wiki.bash-hackers.org
Disk perfomance testing
# Sequential Read
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=test --filename=test.read --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 --filename=test.rw --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
reboot
sudo do-release-upgrade -y