Robot Butler
  Making those complicated tasks nice and easy.
  A hub for guides, walkthroughs and general information.
Follow us on Twitter RSS Feed
Web Useful Plesk SSH Commands
Pubish Date 2010-12-08 11:54:55 Category Web Author Benjamin Hodgetts Comments 3 comments
Article Image 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 domains set up in Plesk:
mysql -uadmin -p`cat /etc/psa/.psa.shadow` -BN -D psa -e "SELECT DISTINCT(name) FROM domains ORDER BY name;"

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 "\n\nEnter 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 -uadmin -p`cat /etc/psa/.psa.shadow` -Aoe

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 "\n\n=== 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 "\n\n=== 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 "\n\n=== 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:/M\t/g'; fi; if [ -d /var/lib/psa/dumps/domains ]; then echo -ne "\n\n=== 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 "\n\n=== TEMP FILES ===\n"; du -hs /tmp /var/tmp; echo -ne "\n\n=== LOGS ===\n"; du -hs /var/log /usr/local/psa/var/log; echo -ne "\n\n";

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 "\n\n"; 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 "\n\n";

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

Comments

Auto-Avatar
xfrost   ~   Posted on 2012-02-29 15:57:43
Nice, thanks!
Auto-Avatar
Victor   ~   Posted on 2013-04-13 12:06:03
wonderful, can you explain me how to uninstall and re install qmail. Many of the binary files are gone in my current installation. all domains are not able to send mails outward. I did use all ssh commands i came through in google. SAD
Auto-Avatar
Benjamin Hodgetts   ~   Posted on 2014-01-20 10:20:08
@Victor: Unfortunately that's rather hard to do here as it will be different for every distro, your best off asking that same question in the support forum for the Linux distro you're currently using.

Post a Comment

    Name
    Email (not displayed)

The name of this website is Robot...      


Info STATISTICS

  • 14 categories
  • 50 articles
  • 137 comments

Site, design and code by Benjamin Hodgetts.