send all accounts list by mail one time per week instead of downloading it

foxmedo

Well-Known Member
Apr 21, 2014
50
1
58
cPanel Access Level
Root Administrator
Dears,

We need a solution to send the accounts list by mail one time per week by instead off downloading the list manually

The information needed is the current storage used by client, package, username, main domain ...

Any help from your side will be really appreciated.

Best regards
 
Last edited by a moderator:

foxmedo

Well-Known Member
Apr 21, 2014
50
1
58
cPanel Access Level
Root Administrator
thank you for your feedback i have create the script you will find it bellow if any one need it

#!/bin/bash

# Get the server hostname
HOSTNAME=$(hostname)

# Run whmapi1 listaccts and output to a csv file
whmapi1 listaccts --output=json | jq -r --arg hostname $(hostname -f) '.data.acct[] | [.user, .domain, .ip, .email, .uid, .owner, .startdate, .unix_startdate, .plan, .diskused, .disklimit, $hostname, .suspended, .suspendtime, .suspendreason, .mailbox_format, .legacy_backup, .backup, .partition, .max_email_per_hour, .inodesused, .inodeslimit, .max_defer_fail_percentage, .outgoing_mail_suspended, .outgoing_mail_hold, .has_backup] | @csv' > accounts.csv

# Convert the csv file to Google Spreadsheet format
sed -i '1s/^/User,Domain Name,IP Address, Email,Account Name,Owner,Start Date, Unix Start Date,Package,Disk Usage,Disk Limit, Server Hostname,Suspended, Suspend time,Suspend reason,Mailbox Format, Legacy Backup, Backup, Partition, Max Email Per Hour, Inodes Used, Inodes Limit, Max Defer Fail Percentage, Outgoing mail suspended, Outgoing mail hold, Has Backup\n/' accounts.csv

# Send the csv file via email
echo "See attached file for list of accounts." | mailx -s "WHM Accounts List $HOSTNAME" -a accounts.csv [email protected]

# Remove the csv file
rm accounts.csv