How to list all website domains and subdomains on server

Post Reply
User avatar
myVesta
Site Admin
Posts: 999
Joined: Fri Jun 19, 2020 9:59 am
Has thanked: 10 times
Been thanked: 6 times

Code: Select all

for user in $(grep '@' /etc/passwd |cut -f1 -d:); do
    if [ ! -f "/usr/local/vesta/data/users/$user/user.conf" ]; then
        continue;
    fi
    for domain in $(/usr/local/vesta/bin/v-list-web-domains $user plain |cut -f 1); do
        echo $domain
    done
done
NordicSnowman
Posts: 14
Joined: Sun Mar 26, 2023 8:52 pm

If i may contribute with this.
I wanted a small script to list all users and domains easy to a txt-file.
I choosed v-list-domains, you can change it to whatever you want not already used by MyVestaCP.

Code: Select all

cd /usr/local/vesta/bin

Code: Select all

nano v-list-domains
Paste the contents from this - do any changes you want for the location of the output-file.

Code: Select all

#!/bin/bash

usage() {
    echo "Usage: $0 [-f] [-l]"
    echo "  -f  Save to file (/root/domains-DATE.txt)"
    echo "  -l  Print to terminal"
    exit 1
}

TO_FILE=false
TO_LIST=false

while getopts "fl" opt; do
    case $opt in
        f) TO_FILE=true ;;
        l) TO_LIST=true ;;
        *) usage ;;
    esac
done

if ! $TO_FILE && ! $TO_LIST; then
    usage
fi
output=()

for user in /usr/local/vesta/data/users/*; do
    user=$(basename "$user")

    domains=$(/usr/local/vesta/bin/v-list-web-domains "$user" plain 2>/dev/null | cut -f1)

    if [[ -n "$domains" ]]; then
        output+=("$(echo "${user^^}")")
        output+=("$domains")
        output+=("")  # blank line
    fi
done

final_output=$(printf "%s\n" "${output[@]}")

if $TO_LIST; then
    echo "$final_output"
fi

if $TO_FILE; then
    OUTFILE="/root/domains-$(date +%Y%m%d).txt"
    echo "$final_output" > "$OUTFILE"
    echo "Saved to: $OUTFILE"
fi
then

Code: Select all

chmod +x v-list-domains
How to use
v-list-domains (shows help-text)
v-list-domains -f (saves the list to a file)
v-list-domains -l (lists it on screen)

The output shows the user + the domains on that account. Like this

Code: Select all

USER1
domain1.xx
domai2.xx

USER2
domain4.xx
subdomain.domain.xx
Post Reply