LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 10-21-2010, 06:08 PM   #1
philaaay
LQ Newbie
 
Registered: Oct 2010
Posts: 1

Rep: Reputation: 0
RHEL Adding User Shell Scripting?


I work at the UW Med School as a student IT technician and just recently, I've started working with Linux. I've used Ubuntu before, but in terms of using RHEL and the terminal and whatnot, I'm fairly a newb on it.

My manager recently wanted me to take on a simple task of e-mailing the students in the department I work at and see if they wanted a Linux administrator account.

(Although the students can use root, we've decided it'd be better for each student to have their own account which can have administrative rights)

Logged in as root, I've started with using:

# usermod -a -G admin username

where I replace username with the actual username of the student.

After doing so, I'd log out and log back in as the student and through Terminal, I'd execute:

sudo -s

which now allows them to use Terminal as root and do what they need to do.

My questions is how do I add multiple usernames at once? Meaning rather than having to go do this process for each individual username (There are about 89 students in the program), how can I write a script where I can insert all the usernames at once and execute all this at once?
 
Old 10-21-2010, 06:26 PM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,608

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Maybe a script like
Code:
#!/bin/bash
while read user; do
usermod -a -G admin  $user
# ... other stuff like default password ?
done
Hit ctrl-d to end it.
More important, read
Code:
man sudoers
I do not think that all 89 members will require full administrative rights. You can limit those rights by configuring the sudoers file.

Since your RHEL comes with a paid subscription I suggest you consult with Redhat for further information and security issues.
 
Old 10-22-2010, 02:26 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,258

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
You should bookmark this if you're going to be using RH/Centos http://www.linuxtopia.org/online_boo...ion/index.html.

Personally, rather than answer a prompt 89 times, I'd grab/generate the list of names into a file and get the prog to read the file instead.
You're prob going to need that list for other things anyway.
Something like
Code:
#!/bin/bash

for user in $(cat users.dat)
do
   usermod -a -G admin  $user
   # ... other stuff like default password ?
done
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 10-22-2010, 05:04 AM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,608

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Quote:
Originally Posted by chrism01 View Post
Personally, rather than answer a prompt 89 times, I'd grab/generate the list of names into a file and get the prog to read the file instead.

That was my first idea, too. But then again, you will have to do the typing anyway when you generate the list. And what about adding users afterwards? Add them to the list and reprocess the complete list again?
Well, chances are, since he is doing that for a university, that the necessary names are already present somewhere in digitalized form. He would just need to filter that information and feed the result into a separate file (or pipe directly?) and then process it. So one could add an argument to process a file or not.
Or
Code:
$ cat myuseradd
#!/bin/bash
# myuseradd
while read user; do
usermod -a -G admin  $user
# ... other stuff like default password ?
done
$ cat file | ./myuseradd
Tested it with echo statement. This way you still can add a user manually and process a file.

Anyway, I think the focus should be on the 'administrative rights' issue. Having 89 'root' users seems a bit excessive.

Last edited by crts; 10-22-2010 at 05:08 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Shell scripting: How to create a user Kenny_Strawn Programming 7 09-05-2010 11:14 PM
bash scripting... taking user input and adding it to a particular area of a file... dagummit Programming 7 01-13-2010 01:07 AM
How to switch user in shell scripting.. Parished.D Linux - Software 2 10-31-2006 08:30 AM
making user friendly screen through shell scripting Prasun1 Linux - General 7 07-09-2005 05:31 AM
Shell scripting - Adding many numbers in an array Stingreen Linux - General 2 10-25-2004 06:25 PM


All times are GMT -5. The time now is 09:46 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration