Shell script case (ii) bulk delete users

Source: Internet
Author: User

Case-then the previous case
Want to bulk delete all users created in the previous case
Script Show: (Next time explain)

#!/bin/bashecho > userlist.txt;for i in `seq 50`do  id student$i >/dev/null 2>/dev/null;  [ $? -ne 0 ] && echo -e "[\033[31merror\033[0m] user student$i not exist." && continue;  userdel -r student$i >/dev/null 2>/dev/null;  [ $? -eq 0 ] && echo -e "[\033[32mok\033[0m] delete user student$i succes."done

Script Run

[[email protected] scripts]# bash rmuser.sh [OK] Delete user Student1 succes. [OK] Delete user Student2 succes. [OK] Delete user Student3 succes. [OK] Delete user student4 succes. [OK] Delete user student5 succes. [OK] Delete user student6 succes. [OK] Delete user student7 succes. [OK] Delete user student8 succes. [OK] Delete user student9 succes. [OK] Delete user student10 succes. [OK] Delete user student11 succes. [OK] Delete user student12 succes. [OK] Delete user student13 succes. [OK] Delete user student14 succes. [OK] Delete user student15 succes. [OK] Delete user student16 succes. [OK] Delete user student17 succes. [OK] Delete user student18 succes. [OK] Delete user student19 succes. [OK] Delete user student20 succes. [OK] Delete user student21 succes. [OK] Delete user student22 succes. [OK] Delete user student23 succes. [OK] Delete user Student24 succes. [OK] Delete user Student25 succes. [OK] Delete user Student26 succes. [OK] Delete user student27 succes. [OK] Delete user student28 succes. [OK] DelEte user student29 succes. [OK] Delete user Student30 succes. [OK] Delete user student31 succes. [OK] Delete user Student32 succes. [OK] Delete user student33 succes. [OK] Delete user Student34 succes. [OK] Delete user Student35 succes. [OK] Delete user student36 succes. [OK] Delete user Student37 succes. [OK] Delete user student38 succes. [OK] Delete user student39 succes. [OK] Delete user student40 succes. [OK] Delete user student41 succes. [OK] Delete user Student42 succes. [OK] Delete user student43 succes. [OK] Delete user Student44 succes. [OK] Delete user student46 succes.  [[email protected] scripts]#

If it does not exist (and then deleted again)

[[email protected] scripts]# bash rmuser.sh [ERROR] user Student1 not exist. [ERROR] User Student2 not exist. [ERROR] User Student3 not exist. [ERROR] User student4 not exist. [ERROR] User student5 not exist. [ERROR] User student6 not exist. [ERROR] User student7 not exist. [ERROR] User student8 not exist. [ERROR] User student9 not exist. [ERROR] User student10 not exist. [ERROR] User student11 not exist. [ERROR] User student12 not exist. [ERROR] User student13 not exist. [ERROR] User student14 not exist. [ERROR] User student15 not exist. [ERROR] User student16 not exist. [ERROR] User student17 not exist. [ERROR] User student18 not exist. [ERROR] User student19 not exist. [ERROR] User student20 not exist. [ERROR] User student21 not exist. [ERROR] User student22 not exist. [ERROR] User student23 not exist. [ERROR] User Student24 not exist. [ERROR] User Student25 not exist. [ERROR] User Student26 not exist. [ERROR] User student27 not exist. [ERROR] User student28 not exist. [ERROR] User student29 not exist. [ERROR] User Student30 not exist. [ERROR] User student31 not exist. [ERROR] User Student32 not exist. [ERROR] User student33 not exist. [ERROR] User Student34 not exist. [ERROR] User Student35 not exist. [ERROR] User student36 not exist. [ERROR] User Student37 not exist. [ERROR] User student38 not exist. [ERROR] User student39 not exist. [ERROR] User STUDENT40 not exist. [ERROR] User student41 not exist. [ERROR] User Student42 not exist. [ERROR] User student43 not exist. [ERROR] User Student44 not exist. [ERROR] User student46 not exist.  [[email protected] scripts]#

To view saved files

Shell script case (ii) bulk delete users

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.