These forums are locked and archived, but all topics have been migrated to the new forum. You can search for this topic on the new forum: Search for Getting more information from command line. on the new forum.
I'm currently writing a script that runs periodically. I wanted to get some information from virtualmin (domain, username, home). Maybe I'm missing something, but this prooves to be more difficult than I expected using the command line API.
I came up with the following bash script to pull pull the information with one virtualmin query, is there a simpler way to do this?
#!/bin/bash
virtualmin_domains=$(virtualmin list-domains --simple-multiline)
while [[ $(echo -n "$virtualmin_domains" | wc -l) -gt 1 ]]; do
# First line is domain
domain=$(echo "$virtualmin_domains" | head -n1)
# Trim the domain name off the input
virtualmin_domains=$(echo "$virtualmin_domains" | tail -n+2)
# Find where the indentation ends (where the next domain starts)
offset_search=$(echo "$virtualmin_domains" | grep -vn "^ ")
# If the search fails, this is the last domain
if [ $? -eq 0 ]; then
# Extract the domain info to process
offset=$(echo "$offset_search" | head -n1 | cut -d':' -f1)
info=$(echo "$virtualmin_domains" | head -n$offset)
# Trim the information off the input
virtualmin_domains=$(echo "$virtualmin_domains" | tail -n+$offset)
else
# This is the last domain. Only the domain info is left
info="$virtualmin_domains"
virtualmin_domains=""
fi
# Process the domain information
home=$(echo "$info" | grep "Home directory:" | cut -d' ' -f7)
user=$(echo "$info" | grep "Username:" | cut -d' ' -f6)
echo "$domain $home $user"
done
If you just want a list of domain names for use in a script, try the command :
virtualmin list-domains --name-only
''