我有带有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中运行,但我无法做到,因为它要求手动响应“是”或“否”。如果有人可以帮助我,我会很棒。
答案 0 :(得分:0)
尝试:
for i in `cat /root/auto.txt`; do echo "y" | /scripts/removeacct -y $i; done