Skip to content

Instantly share code, notes, and snippets.

@rushipkar90
Created September 25, 2015 16:24
Show Gist options
  • Save rushipkar90/cce738e98efc33b6e82c to your computer and use it in GitHub Desktop.
Save rushipkar90/cce738e98efc33b6e82c to your computer and use it in GitHub Desktop.
auto_terminate.sh
#!/bin/bash
# Directory to store log files in
DST=/root/autotermination_logs
# Create DST if it doesn't exist
if [ ! -d "$DST" ]; then
mkdir -p $DST
fi
date_diff() {
echo $(((`date -d $1 +%s`-`date +%s`)/(24*3600)));
}
for s_lst in `ls -A /var/cpanel/suspended`
do
if [ `du -b /var/cpanel/suspended/$s_lst | awk '{print $1}'` -eq 0 ] && [ `date_diff \`date +%Y-%m-%d -r /var/cpanel/suspended/$s_lst\`` -le -30 ];
then
echo -e "\n\n\nTerminating $s_lst on at `date +%r`" >> $DST/terminated-`date +%F`.txt
echo 'y' | /scripts/killacct --killdns $s_lst >> $DST/terminated-`date +%F`.txt
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment