My User management shell script

Subrat YadavSubrat Yadav
2 min read

Access the code on GitHub

I came across a beginner friendly challenge to create a user management script where task was to create a bash script that provides options for managing user accounts on the system. The script should allow users to perform various user account-related tasks based on command-line arguments.

Actions like :

  • User Creation

  • User Deletion

  • Password reset

  • Listing all users

Although task seems simple for creating a user or deleting one, but for me it was a bit complicated first I need to figure out the commands for that , and I could just have asked a AI tool like copilot or chatgpt to complete this task but what is the point if I dont do this by myself, So being a novice learner I divided the task into 4 parts ( user creation, deletion, password reset, listing users)

Then I went to google the commands for creation of user account and I fount the command “ useradd “ and tried creating a user, then implement the logic in shell script and faced some syntax errors. But it worked out. After that the part for deleting had 2 options you could delete a user account and keep their home directory intact or delete altogether, then the part of the password reset was as smooth as butter.

But then I stuck at the problem on the 4th sub task to list all the users because the command found on the websites were just reading from the /**etc/passwd but the list which I am getting was not only the user account but also all the content of the passwd file which was not required after checking out the StackOverFlow for some time I came across a user mentioning the solution which was using awk command and a used a condition to make use that the user ID gets between 1000 - 65534 which helped to distinguish the user account from the other content. So that sort this task

After that I have to write the part of the help section to guide user what this file can do the typical (—help) section or command. If more complexities can be added do let me know it will help to me advance in this Learning journey. Thank you for reading.

0
Subscribe to my newsletter

Read articles from Subrat Yadav directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Subrat Yadav
Subrat Yadav