delete.sh 1.7 KB

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