Command Line API Examples


The following are a set of command line API snippets for performing tasks on a Virtualmin server. Most of them can be put into a text file, and run as a shell script.

List all users on the server, what Virtualmin Plan they're using, and their email address

#!/bin/sh
virtualmin list-plans --name-only | while read plan; do
         echo $plan
         echo "------------------------------"
         virtualmin list-domains --multiline --toplevel --plan "$plan" | grep -e '^\S' -e "Contact email:" | sed -e 's/Contact email: //'
         echo
done

Regenerate Apache VirtualHost information using the latest data from the Apache Website section in the Server Templates

#!/bin/sh
doms=virtualmin list-domains --with-feature web --name-only
for dom in $doms; do
  virtualmin disable-feature --domain $dom --web --webalizer --logrotate
  virtualmin enable-feature --domain $dom --web --webalizer --logrotate
done

Convert server using writelogs.pl to storing logs in /var/log/virtualmin/

#!/bin/sh
mkdir /var/log/virtualmin/
for dom in virtualmin list-domains --with-feature web --name-only; do
  virtualmin disable-writelogs --domain $dom
  virtualmin modify-web --domain $dom --access-log /var/log/virtualmin/${dom}_access_log
  virtualmin modify-web --domain $dom --error-log /var/log/virtualmin/${dom}_error_log
done

Reset passwords for all Virtual Server owners

for dom in virtualmin list-domains --name-only --toplevel; do
  virtualmin modify-domain --domain $dom --pass XXX
done

Reset passwords for all Email, FTP, and Database users

for dom in virtualmin list-domains --name-only; do
      for user in virtualmin list-users --domain $dom --name-only; do
            virtualmin modify-user --user $user --domain $dom --pass XXX
      done
done