用于从 Linux 服务器自动删除已暂停帐户的脚本

用于从 Linux 服务器自动删除已暂停帐户的脚本

我有一台安装了 CentOS 的 Linux 托管服务器,上面安装了 WHM。为了减少磁盘空间的成本和误用,我创建了一个 shell 脚本,可以自动删除已暂停超过 30 天但仍在使用服务器空间的暂停帐户。

脚本:

root@ping [~]# cat autoterminate.sh
#!/bin/bash

find /var/cpanel/suspended/ -mtime +30 > autoterminate.txt

cut -d '/' -f5 /root/autoterminate.txt
echo "Users to remove"

cut -d '/' -f5 /root/autoterminate.txt > auto.txt

for i in `cat /root/auto.txt`; do /scripts/removeacct -y $i; done

当我运行该脚本时,它会要求我做出是或否的回应。

root@ping [~]# ./autoterminate.sh

swicsor    #this is the user which i found suspended more than 30 days

Users to remove
Unknown option: y
Are you sure you want to remove the account "swicsor", and DNS zone files for the user? [y/N]?

基本上,我希望这个脚本在 cronjob 中运行,但我无法做到这一点,因为它要求手动响应“是”或“否”。如果有人能帮助我,我将非常感激。

答案1

伊恩更正确 使用适当的论点
也许这就是您应该做的,尽管我没有运行 CPanel,因此无法测试。

#!/bin/bash
for suspendedUser in $(find /var/cpanel/suspended/ -mtime +30 | cut -d '/' -f5) ; do
    /scripts/removeacct $suspendedUser --force
done

最初的轻率回应:

yes(1)

for i in `cat /root/auto.txt`; do yes | /scripts/removeacct $i; done

相关内容