Commonly Used Advanced Linux Commands

Home » Commonly Used Advanced Linux Commands

Note: All commands to be run as root user unless otherwise specified. This is my go to cheat sheet for fast complex commands for troubleshooting servers almost every day. Hope you enjoy!

Restart Plesk

service psa restart

Restart all Mail Services on Plesk

service courier-imaps stop
service courier-imaps start
service courier-imapd stop
service courier-imapd start
service courier-pop3d stop
service courier-pop3d start
service courier-pop3s stop
service courier-pop3s start

Restart PHP FPMS on Plesk

service plesk-php70-fpm restart
service plesk-php72-fpm restart
service plesk-php73-fpm restart
service plesk-php56-fpm restart

Restart MySQL

Explanation: Run this when Plesk login isn’t loading (common for Halloween).

/etc/init.d/mysql restart

Ban IP addresses

iptables -I INPUT -s 180.93.100.126 -p tcp -j DROP

or if the server has apf on it:

apf -d <ip>

Server Status Page

Should you need to set up server status on a server without it enabled, these instructions should work for servers even non plesk servers: https://support.plesk.com/hc/en-us/articles/213922425-How-to-enable-the-Apache-server-statistics-on-a-Plesk-server

Confirm IP address properly banned

iptables -L INPUT -v -n | grep "180.93.100.126"

Find unique ips hitting a specific url endpoint in apache logs

This is specifically “notifystock” endpoint.

cat access_ssl_log | grep notifystock | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -20

Get Largest Files on server

resize; clear; date; echo "Largest Directories:"; du -hcx / | grep '^[0-9]*G'\
| sort -nr | head; echo ""; echo "Largest Files:"; nice -n 19 find / -mount \
-type f -ls|sort -rnk7 |head -40|awk '{printf "%d MB\t%s\n",($7/1024)/1024,$NF}'

Get Inode usage of folders

find . -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn

Block Bot Army on specific url with apf

If a bot army is hitting a url “account/create” you can use the below commands to block them.

grep "account/create" access_ssl_log > brian
awk '{print $1}' brian | sort -u > brian2
sed 's/^/apf -d /' brian2 >> block.sh
sh block.sh

Rsync Example

rsync -avz -e "ssh -p 28804" root@sourcexyz.com:/root/install.log /tmp/
rsync -avz -e "ssh -p 28804" --perms --delete /home/user/ root@108.xx.xxx.xxx:/home/user/

Better TOP (TOP alternative)

atop -Aac “`

First, you may need to yum install atop

ionice process/es by name

Replace “/usr/bin/imapd” with name of the process:

ps axf | grep "/usr/bin/imapd" | grep -v couriertls | grep -v grep | awk '{print "sudo ionice -c2 -n7 -p " $1}'|sh

If you want to test before running:

ps axf | grep "/usr/bin/imapd" | grep -v couriertls | grep -v grep | awk '{print "sudo ionice -c2 -n7 -p " $1}'

Change MTA from qmail to postfix on plesk server

This command should not be run unless you are 1000% sure you know what you are doing and all of the risk associated with it. /usr/local/psa/admin/sbin/autoinstaller --select-release-current --install-component postfix

Sar Command

This command keeps track of iowait and a few other things on the server. Can be used to verify if there were issues previously.

[root@host.com httpdocs]# sar
Linux 2.6.32-696.1.1.el6.x86_64 (host.com)     03/09/2019  _x86_64_    (8 CPU)

12:00:01 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
12:10:01 AM     all      0.49      0.71      0.36      1.13      0.03     97.28
12:20:01 AM     all      0.33      3.08      2.22      0.51      0.07     93.79
12:30:01 AM     all      0.56      2.45      0.79      0.17      0.00     96.02
12:40:01 AM     all      0.85      1.68      3.87      0.28      0.01     93.31
12:50:01 AM     all      0.35      0.40      2.79      0.43      0.01     96.02
01:00:01 AM     all      0.29      0.34      0.33      0.12      0.00     98.92
01:10:02 AM     all      0.43      0.32      5.03      6.62      0.02     87.58
01:20:01 AM     all      0.86      0.69     10.02     12.03      0.02     76.38
01:30:01 AM     all      0.65      0.48      1.88      5.09      0.01     91.89

Print top Disk usage processes

iotop

Then press ‘a’ on the keyboard once it loads to sort by aggregate. Note: if there are magento crons running and very high load, it is usually ok to kill with kill -9 <pid>. Check that the site loads after killing. If it doesn’t for some reason, you can simply rerun the indexer via ssh for that site.

Print top CPU usage processes

ps aux | sort -nrk 3,3 | head -n 5

Print out top requester ips on plesk

cat /var/www/vhosts/*/logs/access_log /var/www/vhosts/*/logs/proxy_access_log /var/www/vhosts/*/logs/proxy_access_ssl_log /var/www/vhosts/*/logs/access_ssl_log | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -100

Leave a Comment

Your email address will not be published. Required fields are marked *