Sh3ll



Directory :  /scripts2/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

Current File : //scripts2/cpanel_new_mailbox.sh
#!/bin/bash
#
# uapi: create mail accounts with the 1st (user@domain), 3rd (password)
# and 4th (quota) fields in the input file.
#

if ! jq --help > /dev/null; then
  echo "jq must be installed."
  exit 1
fi

USER=$1
SRC=$2

> mailbox_create_ok.txt
> mailbox_create_error.txt

{ while IFS=';' read mailbox IGNORE newpass quota
    do
      IFS='@';read mail_user mail_domain <<< "$mailbox"

      uapi_stat=$(uapi --output=json \
                       --user="$USER" \
                  Email add_pop \
                      email="$mail_user" \
                     domain="$mail_domain" \
                   password="$newpass" \
                      quota="$quota" \
                  | jq '.result.errors[0]')

      if [[ "$uapi_stat" == 'null' || "$uapi_stat" == "The account $mailbox already exists!" ]]
      then
        echo "$mailbox: mailbox was created successfully." | tee -a mailbox_create_ok.txt
      else
        echo "$mailbox: could not create mailbox -> $uapi_stat." | tee -a mailbox_create_error.txt
      fi
   
    done

  echo "$USER: finished. Logs available in mailbox_create_ok.txt, mailbox_create_error.txt."

} < "$SRC"

Sh3LL