Visit Our UNIX and Linux User Community


Using userdel -r in a script? To delete multiple users.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using userdel -r in a script? To delete multiple users.
# 1  
Old 10-14-2009
Using userdel -r in a script? To delete multiple users.

I'm getting ready to upgrade to Solaris 10 (from 8) and I'm trying to write a script that will delete approximately 800 user accounts that are no longer required. I'm trying to use the userdel -r command and read the input from a file with the list of user names. I've never been very good at scripting and I'm at a lost as to where to start.

Thanks,

---------- Post updated 10-14-09 at 12:30 PM ---------- Previous update was 10-13-09 at 09:04 PM ----------

Code:
#!/bin/ksh
#
for user in $(< dellist.txt)
do
  userdel -r $user
done
#

Thanks anyone who is working this! I found my scripting book and started reading last night.

Last edited by pludi; 10-16-2009 at 03:22 AM.. Reason: code tags please...
# 2  
Old 10-15-2009
Personally I'd do it like this:
Code:
#!/bin/ksh
#
cat dellist.txt | while read user
do
        echo "Deleting: ${user}"
        echo userdel -r "${user}"
done

Remove echo on "userdel" line after thorough testing.

Ps. I know about UUOC but disagree.

Last edited by pludi; 10-28-2009 at 09:49 AM..
# 3  
Old 10-15-2009
Thanks! That worked also. The only problem was that with TSOL the -r didn't work. So I just repeated my for statement as follows.
Code:
#!/bin/ksh
#
for user in $(< dellist.txt)
do
userdel r $user
done
#
for user1 in $(< dellist.txt)
do
rm -rM /home/$user1
done
#

PS. I don't mind the UUOC. Smilie

Last edited by pludi; 10-16-2009 at 03:22 AM.. Reason: co
# 4  
Old 10-16-2009
Will do in the future. Sorry

Previous Thread | Next Thread
Test Your Knowledge in Computers #217
Difficulty: Medium
Network operating systems can be embedded in a router or hardware firewall that operates the functions in the physical layer (layer 1).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for creating multiple users with password

for UserName in `cat users` ; do useradd -d /u02 -s /usr/libexec/openssh/sftp-server -G ftp-users $UserName ; PassWord=$( echo $( tr '' '' <<< ${UserName:0:1} )${UserName:1} ) ; echo "$PassWord@123" | passwd $UserName --stdin ; done can some one explain what the bold text do Please use... (5 Replies)
Discussion started by: James0806
5 Replies

2. Shell Programming and Scripting

Script to delete users in the servers

Hi Team, Hope you are doing good.I am new to scripting.I have a requirement of deleting around 10 users in 100 servers.It is very time consuming by logging into each servers and delete the user.Here I have redhat 6 ,Suse linux 10&11 environment servers. In one set of servers I have... (5 Replies)
Discussion started by: muraliinfy04
5 Replies

3. Shell Programming and Scripting

Script To Delete User Accounts On Multiple Servers

Hello All, The servers in question are AIX/Unix servers. I was hoping to find a scripting solution where I could use one server as a jump server and run a script that would check each server for a user account (the source file for the user accounts would be a text file or csv file) , and delete... (4 Replies)
Discussion started by: k45bryant
4 Replies

4. Homework & Coursework Questions

Script to delete multiple users

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hi This is my first post.I am learning Unix and finding it difficult to get a handle on the scripting side of... (5 Replies)
Discussion started by: dom17
5 Replies

5. Shell Programming and Scripting

Script to add new users to a group on multiple servers using SSH

Hi Experts, I am new to scripting. We have around 400 Linux servers in our environment. I want to add a new user to a perticular group on all the servers using SSH. Requirements: 1) Need to take the server names from a text file. 2) Login into each server and check whether perticular... (1 Reply)
Discussion started by: Satya1983
1 Replies

6. Shell Programming and Scripting

Create multiple users with individual passwords to users

hi, i am new to shell scripts i write a shell script to create multiple users but i need to give passwords to that users while creating users, command to write this script (1 Reply)
Discussion started by: DONFOX
1 Replies

7. Shell Programming and Scripting

script to delete multiple files in remote machine

Requirement Several files in remote machines ought to be deleted via sh. Name of the files to be deleted are know Approach 1) script was written with ftp (requires credential) and delete command. File names were passed as array(iterated via for loop-with ftp+delete commands enclosed within... (1 Reply)
Discussion started by: vkalya
1 Replies

8. Shell Programming and Scripting

Need Script to delete multiple entries from a file

I am new to Linux and would appreciate some help. I need a script to do the following: My file contains the following entries more file 1 1 1 1 2 2 2 I want to delete multiple entries of 1 and 2 and just keep one of each. The output should look like more file 1 2 Thanks (1 Reply)
Discussion started by: sidewayz
1 Replies

9. Shell Programming and Scripting

Script to delete all data from multiple files

its urgent!!!!!!111 i need a script which can delete data from multiple files. plz if anybody knows the script plz write a mail to me : (Email addresses are not allowed) (5 Replies)
Discussion started by: uni_ajay_r
5 Replies

10. UNIX for Dummies Questions & Answers

Need a script to delete multiple files

Hello, I am working with about 500,000 text files and 90% of them are duplicates. I need a way to delete the duplicate ones. The files are email messages with the following file name examples: 20040129-1457 This is the Subject line.txt 20040129-1457 This is the Subject line-1.txt... (3 Replies)
Discussion started by: navycow
3 Replies

Featured Tech Videos