-2

I have Linux hosting server with centOS, which have WHM installed on it. To reduce the costing and mis-usage of Disk space i am creating a shell-script which automatically removes the suspended accounts which are suspended for more than 30 days and still using space on server.

Script:

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

When i run this script it is asking for yes or no response from my side.

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]?

Basically i want this script to run in cronjob, but i am unable to do it, as it is asking manual response of "Yes" or "No". I will be great if anyone there can help me out.

MadHatter
  • 79,770
  • 20
  • 184
  • 232
imvikasmunjal
  • 753
  • 7
  • 14

1 Answers1

3

Iain is much more right use the proper argument.
Here's, perhaps, what you ought to do, though I run no CPanel so cannot test.

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

Original flippant response:

yes(1)

for i in `cat /root/auto.txt`; do yes | /scripts/removeacct $i; done
84104
  • 12,905
  • 6
  • 45
  • 76
  • Ah, the old ones are... the oldest. +1 from me for another elegant use of an old favourite. – MadHatter Mar 30 '16 at 06:11
  • Why would you do that when ther is a command line option ? Seriously, if the cluefull people can't read teh docs why should we expect the clueless tl do so. – user9517 Mar 30 '16 at 06:13
  • Yes | /scripts/removeacct i added in the above script and its not useful. – imvikasmunjal Mar 30 '16 at 06:15
  • @MadHatter There is of course an older and better method - RTFM – user9517 Mar 30 '16 at 06:16
  • @Iain It's still late for me, I was being a bit flippant. cpanel is outside of my skill set. If I were being more serious, I'd probably consolidate the script down to a single `find`. – 84104 Mar 30 '16 at 06:18
  • @Iain I had no idea `/scripts/removeacct.sh` was a cpanel built-in; I'd assumed it was Yet Another Home Grown Thingy. I guess this is why we don't really like cpanel questions around these parts. Given what you've said, what can I add: you're right. RTFM, OP! (But 84104, I still sneakingly like seeing `yes` get another outing!) – MadHatter Mar 30 '16 at 06:18
  • basically this script will help in removing the suspended accounts for more than 30 days, which are not hosted anymore on server. I want to run cronjob of this script on regular basis to check the suspended accounts and remove them from server. /scripts/removeacct is used to remove any account manually. – imvikasmunjal Mar 30 '16 at 06:19
  • @MadHatter nor did I but for all we're down on cPanel here because it brings in cluelessness (see above) they actually have great support and excellent documentation. If only people who are paying for it would use it. – user9517 Mar 30 '16 at 06:24
  • @Iain I have a dream ... – MadHatter Mar 30 '16 at 06:25
  • I shared my invested time and outputs on the website. I don know why this question is down-voted? – imvikasmunjal Mar 30 '16 at 06:34
  • 1
    @imvikasmunjal I can't be sure, but I figure the reason I was downvoted was my incompetence. – 84104 Mar 30 '16 at 06:50
  • 1
    @imvikasmunjal mouse over the down arrow; the popup says "*This question does not show any research effort; it is unclear or not useful*". Downvotes without comment may be presumed to be for at least one of those reasons. – MadHatter Mar 30 '16 at 06:51
  • @MadHatter I probably wouldn't even have answered if this hadn't made me think of `yes(1)`. After this I fear for the trouble I'll get into if something reminds me of `tac(1)`. – 84104 Mar 30 '16 at 06:58
  • 2
    @imvikasmunjal I downvoted your question because it shows a lack of research. I don't have a WHM/cPanel server to hand but it took me 30 seconds to find the documentation for the utility you are using and see that there was a command line option that did what you wanted. I can't believe that writing a question was quicker than that. Having someone else read the documentation for you does not educate you. – user9517 Mar 30 '16 at 07:01
  • Thanks @lain for the beautiful comment. +1 for the comment. It would be more useful if you can tell me the exact flag, coz i searched around for this firstly and then raised the question. – imvikasmunjal Mar 30 '16 at 07:17
  • @imvikasmunjal Did you even follow Iain's link? The one posted right under your question, that sends you to a page that contains the answer? – Jenny D Mar 31 '16 at 07:46