LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2010, 07:06 AM   #1
Sharlene
LQ Newbie
 
Registered: Sep 2010
Posts: 4

Rep: Reputation: 0
Script for unlocking multiple users


Good Afternoon,

I’d like to create a script to unlock multiple users rather than entering the command manually for each user.

I’m quite new to Linux and have not done any scripting so far. Could you tell me if it’s possible to achieve what I want, and possibly provide examples or point me in the right direction?

We are using RHEL 5.

Any help is much appreciated.

Kind Regards
Sharlene
 
Old 09-01-2010, 07:13 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Assuming you are using usermod -l username:

for thisuser in user1 user2 user3; do usermod -l $thisuser; done

Or, if the users are in a file (one user per line):

for thisuser in `cat file.with.users`; do usermod -l $thisuser; done

The above 2 examples are one-liners and can be entered from the command line. If an actual script is needed (taking second example as base):
Code:
#!/bin/bash

for thisuser in `cat file.with.users`
do 
  usermod -l $thisuser
done
Hope this helps.
 
Old 09-01-2010, 07:14 AM   #3
Chirel
Member
 
Registered: Nov 2009
Posts: 55

Rep: Reputation: 19
let's say you have a list of users to unlock in users.txt, you could for example :

Code:
for i in $(cat users.txt); do password -u $i; done
Edit: druuna was faster

Last edited by Chirel; 09-01-2010 at 07:15 AM.
 
Old 09-01-2010, 07:31 AM   #4
Sharlene
LQ Newbie
 
Registered: Sep 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Hi,

Thanks for getting back to me.

I probably should have mentioned. I only have access to a few commands, so usermod does not work for me.

When unlocking accounts the only command I can run is:

sudo /usr/bin/passwd -l 'username'
 
Old 09-01-2010, 07:47 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Quote:
When unlocking accounts the only command I can run is:

sudo /usr/bin/passwd -l 'username'
You can still use the examples given. Change usermod -l with sudo /usr/bin/passwd -l

Hope this helps.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
add multiple users(Script) amer_58 Programming 22 02-22-2013 09:09 AM
Multiple Autologins; Multiple Users; Multiple Sessions mrclisdue Linux - Desktop 1 09-26-2007 05:50 AM
Script to create multiple directories under users homes shawnbishop Linux - Software 4 03-30-2006 08:11 AM
bash script for adding multiple users pilipk01 Linux - Newbie 4 01-12-2004 10:05 PM
script for creating multiple users d3funct Programming 1 08-21-2001 05:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration