• Hi, Pleskians! We are running a UX testing of our upcoming product intended for server management and monitoring.
    We would like to invite you to have a call with us and have some fun checking our prototype. The agenda is pretty simple - we bring new design and some scenarios that you need to walk through and succeed. We will be watching and taking insights for further development of the design.
    If you would like to participate, please use this link to book a meeting. We will sent the link to the clickable prototype at the meeting.
  • Our UX team believes in the in the power of direct feedback and would like to invite you to participate in interviews, tests, and surveys.
    To stay in the loop and never miss an opportunity to share your thoughts, please subscribe to our UX research program. If you were previously part of the Plesk UX research program, please re-subscribe to continue receiving our invitations.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.

Resolved Get list of domains and their webroot path in one query?

gbotica

Regular Pleskian
Hi,

I note this useful query to get all domains and their IP addresses from https://kb.plesk.com/en/116917

Code:
# mysql -uadmin -p`cat /etc/psa/.psa.shadow` -Dpsa -e"SELECT dom.id, dom.name, ia.ipAddressId, iad.ip_address FROM domains dom LEFT JOIN DomainServices d ON (dom.id = d.dom_id AND d.type = 'web') LEFT JOIN IpAddressesCollections ia ON ia.ipCollectionId = d.ipCollectionId LEFT JOIN IP_Addresses iad ON iad.id = ia.ipAddressId"

Returns:
Code:
+----+-------------------------------+-------------+------------+
| id | name                          | ipAddressId | ip_address |
+----+-------------------------------+-------------+------------+
| 21 | domain1.tld                   |           1 | 10.0.0.1   |
| 36 | domain2.tld                   |           1 | 10.0.0.1   |
| 38 | domain3.tld                   |           2 | 10.0.0.2   |
| 26 | domain4.tld                   |           2 | 10.0.0.2   |
+------------------------------------+-------------+------------+

Could anyone rewrite this to select all domains and the webroot path in a space delimited list (or something...)
Code:
domain1.tld /var/www/vhosts/domain1.tld/httpdocs
domain2.tld /var/www/vhosts/domain2.tld/httpdocs
.. etc

That would be really useful for looping through in BASH scripts. Currently I use:

Code:
/usr/local/psa/bin/domain --list

and then loop through each domain, executing:

Code:
/usr/local/psa/bin/domain --info

and then grep the result to get the wwwroot path.

A single DB query would be so much easier ... is this possible?

Thanks.
 
Try to use something like:

# plesk db "SELECT dom.id, dom.name, h.www_root FROM domains dom LEFT JOIN DomainServices d ON (dom.id = d.dom_id AND d.type = 'web') LEFT JOIN hosting h ON h.dom_id = dom.id"
 
Try to use something like:

# plesk db "SELECT dom.id, dom.name, h.www_root FROM domains dom LEFT JOIN DomainServices d ON (dom.id = d.dom_id AND d.type = 'web') LEFT JOIN hosting h ON h.dom_id = dom.id"

Fantastic, thanks!
 
Try to use something like:

# plesk db "SELECT dom.id, dom.name, h.www_root FROM domains dom LEFT JOIN DomainServices d ON (dom.id = d.dom_id AND d.type = 'web') LEFT JOIN hosting h ON h.dom_id = dom.id"

Can I format the output of
Code:
plesk db
? (links to 12.0 CLI docs seem to be broken...)

I need to use -s and -N for format the result so I can loop over it in a BASH script.
 
You can use the same

# mysql -uadmin -p`cat /etc/psa/.psa.shadow` -Dpsa -e "select..."

with all necessary format options.
 
Back
Top