Script to terminate suspended accounts on a cPanel server

How to check suspended accounts on a cPanel server and terminate them after a specific time frame?

Many a times you suspend an account on the server and it goes unnoticed for months thus wasting disk space of your server. You can use the following script and schedule it to execute, say once in a day which will delete the suspended accounts from the server.

Create a file called terminatesuspended.sh

# pico /root/terminatesuspended.sh

Add the following code

for i in `find /var/cpanel/suspended/ -mtime +30 |\
  cut -d'/' -f5 | sed '1 d'` 
 do 
 y | /scripts/killacct $i;
 done;

The username of suspended accounts are saved under the /var/cpanel/suspended directory. The find command will search the /var/cpanel/suspended/ directory for files which are 30 days old and will pass the username to the ‘killacct’ command.

Save the file and set a cronjob to execute the file once in a day. Edit the root cronjob file

# crontab -e

Add the following cronjob

0 1 * * * /bin/sh /root/terminatesuspended.sh

The above cronjob will terminate the account that is been suspended from more than 30 days at 1.00AM.

This entry was posted on Monday, June 7th, 2010 and is filed under Scripts. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.