delete.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. red='\e[1;31m'
  3. green='\e[0;32m'
  4. NC='\e[0m'
  5. MYIP=$(wget -qO- icanhazip.com);
  6. echo "Checking VPS"
  7. clear
  8. hariini=`date +%d-%m-%Y`
  9. echo "Thank you for removing the EXPIRED USERS"
  10. echo "--------------------------------------"
  11. cat /etc/shadow | cut -d: -f1,8 | sed /:$/d > /tmp/expirelist.txt
  12. totalaccounts=`cat /tmp/expirelist.txt | wc -l`
  13. for((i=1; i<=$totalaccounts; i++ ))
  14. do
  15. tuserval=`head -n $i /tmp/expirelist.txt | tail -n 1`
  16. username=`echo $tuserval | cut -f1 -d:`
  17. userexp=`echo $tuserval | cut -f2 -d:`
  18. userexpireinseconds=$(( $userexp * 86400 ))
  19. tglexp=`date -d @$userexpireinseconds`
  20. tgl=`echo $tglexp |awk -F" " '{print $3}'`
  21. while [ ${#tgl} -lt 2 ]
  22. do
  23. tgl="0"$tgl
  24. done
  25. while [ ${#username} -lt 15 ]
  26. do
  27. username=$username" "
  28. done
  29. bulantahun=`echo $tglexp |awk -F" " '{print $2,$6}'`
  30. echo "echo "Expired- User : $username Expire at : $tgl $bulantahun"" >> /usr/local/bin/alluser
  31. todaystime=`date +%s`
  32. if [ $userexpireinseconds -ge $todaystime ] ;
  33. then
  34. :
  35. else
  36. echo "echo "Expired- Username : $username are expired at: $tgl $bulantahun and removed : $hariini "" >> /usr/local/bin/deleteduser
  37. echo "Username $username that are expired at $tgl $bulantahun removed from the VPS $hariini"
  38. userdel $username
  39. fi
  40. done
  41. echo " "
  42. echo "======================================"
  43. echo "Script are successfully run"