Useful Plesk SSH Commands

0
2567

Useful Plesk SSH Commands

Below is a list of commands that can be run from a Linux shell session (i.e. over SSH) which will make administering a Plesk server much easier. Firstly because they can give you a lot of information at once which otherwise you would have to trawl through the web interface for, also more important features such as being able to find the usernames and passwords for different accounts (FTP, email, etc).All the commands below assume that you are logged onto the server that hosts Plesk via a SSH session as root or sat directly at the machine.

To show the Plesk admin account password:
cat /etc/psa/.psa.shadow

To remove lockout from the admin user:
mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e “delete from lockout where login=’admin'”

To kill the admin session to allow another user to log in:
mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e “delete from sessions where login=’admin'”

To show all FTP users, their password and their domain:
mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e “SELECT home AS ‘HOMEDIR’, login AS ‘USERNAME’, password AS ‘PASSWORD’ FROM sys_users S, accounts A WHERE S.account_id = A.id ORDER BY home,account_id;”

To show all mailboxes, the usernames, passwords and associated domain:
mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e “SELECT name AS ‘DOMAIN’, mail_name AS ‘USERNAME’, password AS ‘PASSWORD’, postbox as ‘MAILBOX?’, redir_addr as REDIRECT FROM mail M, domains D, accounts A WHERE M.account_id = A.id AND M.dom_id = D.id ORDER BY name,mail_name;”

List all email addresses on the server:
mysql –skip-column-names -B -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e “SELECT CONCAT(mail_name, ‘@’, name) FROM mail M, domains D, accounts A WHERE postbox = ‘true’ AND M.account_id = A.id AND M.dom_id = D.id ORDER BY name,mail_name;”

To show mailboxes with a specific username, paste this and enter the name when prompted:
echo -e “nnEnter mailbox username”; read mbuser; echo ”; mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e “SELECT name AS ‘DOMAIN’, mail_name AS ‘USERNAME’, password AS ‘PASSWORD’ FROM mail M, domains D, accounts A WHERE postbox = ‘true’ AND M.account_id = A.id AND M.dom_id = D.id AND mail_name = ‘${mbuser}’ ORDER BY name,mail_name;”

To fix and optimise all MySQL databases and tables (i.e. to fix crashed or corrupted tables):
mysqlcheck –auto-repair –optimize -uadmin -p`cat /etc/psa/.psa.shadow` –all-databases

To show all MySQL processes and the process owner:
mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e “show full processlist”

To show the size of all websites, mailboxes, databases, backups and logs sorted by size:
clear; if [ -d /var/www/vhosts ]; then echo -ne “nn=== WEBSITES ===n”; cd /var/www/vhosts && du -ks –exclude=’chroot’ –exclude=’default’ * | sort -nr | cut -f2 | xargs du -sh; echo “[`ls –ignore=’chroot’ –ignore=’default’ | wc -l` Sites – Total `du -hs . | cut -f1`]”; fi; if [ -d /var/qmail/mailnames ]; then echo -ne “nn=== MAILBOXES ===n”; cd /var/qmail/mailnames && TMB=$(du -ks */* 2>/dev/null | sort -nr | cut -f2); if [ -n “$TMB” ]; then echo “$TMB” | xargs du -sh; fi; echo “[`find . -mindepth 2 -maxdepth 2 -type d | wc -l` Mailboxes – Total `du -hs | cut -f1`]”; fi; if [ -d /var/lib/mysql ]; then echo -ne “nn=== MySQL DATABASES ===n”; mysql -uadmin -p`cat /etc/psa/.psa.shadow` -e “SELECT round(sum( data_length + index_length )/1024/1024,0) ‘SM’, table_schema ‘DN’ FROM information_schema.TABLES GROUP BY table_schema ORDER BY SM DESC G;” | sed ‘/***/d’ | sed ‘s/SM: //’ | sed ‘:a;N;$!ba;s/nDN:/Mt/g’; fi; if [ -d /var/lib/psa/dumps/domains ]; then echo -ne “nn=== PLESK BACKUPS ===n”; cd /var/lib/psa/dumps/domains && du -ks * | sort -nr | cut -f2 | xargs du -sh; echo “[Total `du -hs . | cut -f1`]”; fi; echo -ne “nn=== TEMP FILES ===n”; du -hs /tmp /var/tmp; echo -ne “nn=== LOGS ===n”; du -hs /var/log /usr/local/psa/var/log; echo -ne “nn”;

To show all MySQL users and their allowed access host:
mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e “select host, user from mysql.user;”

To show all MySQL databases, usernames and passwords on every domain:
mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e “SELECT d.name AS DOMAIN, db.name AS DB, du.login as USER, a.password as PASS FROM db_users du, data_bases db, domains d, accounts a WHERE du.db_id = db.id AND db.dom_id=d.id and du.account_id=a.id ORDER BY d.name, db.name;”

To show all information for a specific domain. Just replace example.org with the domain name in question:
QDNAME=”example.org”; echo -e “nn”; mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -Dpsa -e “SELECT login AS ‘FTP Username’, password AS ‘Password’ FROM sys_users S, accounts A WHERE S.account_id = A.id AND home LIKE ‘%/$QDNAME’ ORDER BY home,account_id; SELECT mail_name AS ‘Mailbox Username’, password AS ‘Password’, postbox as ‘Mailbox?’, redir_addr as ‘Redirect to’ FROM mail M, domains D, accounts A WHERE M.account_id = A.id AND M.dom_id = D.id AND name = ‘$QDNAME’ ORDER BY name,mail_name; SELECT db.name AS ‘Database Name’, du.login as ‘DB Username’, a.password as ‘Password’ FROM db_users du, data_bases db, domains d, accounts a WHERE du.db_id = db.id AND db.dom_id=d.id and du.account_id=a.id AND d.name = ‘$QDNAME’ ORDER BY d.name, db.name;”; echo -e “nn”;

To delete all emails currently in the QMail queue:
service qmail stop && find /var/qmail/queue/{mess,intd,local,remote,todo,info}/ -type f -exec rm {} ; && service qmail start

 …..