LinuxQuestions.org
Review your favorite Linux distribution.
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 12-03-2015, 10:56 AM   #1
linuxman94
LQ Newbie
 
Registered: Dec 2015
Posts: 1

Rep: Reputation: Disabled
I'm trying to write a script to add users non-interactively


The script should read the names of the users (each on a line by themselves) from STDIN

It should set the password (to the user’s name), ensure directory creation, and lock the account after creation.

Your script should check to see if the user already exists and NOT attempt to add the user if the user exists by using `cat /etc/passwd | grep $username` to check and see if empty

should run like: cat /root/users | ./addusers.bsh

I've been stuck on this for a while, can anyone help me out?
 
Old 12-03-2015, 11:45 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by linuxman94 View Post
The script should read the names of the users (each on a line by themselves) from STDIN
Use read in a while loop.

Quote:
Originally Posted by linuxman94 View Post
It should set the password (to the users name), ensure directory creation, and lock the account after creation.
Use passwd and mkdir.

Quote:
Originally Posted by linuxman94 View Post
Your script should check to see if the user already exists and NOT attempt to add the user if the user exists by using `cat /etc/passwd | grep $username` to check and see if empty
That is known as cat abuse. My script never does that.

Quote:
Originally Posted by linuxman94 View Post
should run like: cat /root/users | ./addusers.bsh
I've been stuck on this for a while, can anyone help me out?
More cat abuse.

Anyway, show us what you have tried so far. I doubt anybody here will write a script for you from scratch for free.

Last edited by berndbausch; 12-03-2015 at 11:47 AM.
 
Old 12-03-2015, 12:02 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Step 1) Ignore the script part of this assignment. How do you create a user, create its home directory, set its password, and lock it on the command line? Once you know what commands you need, stick them in a file and call it a script. That's all a script is, a sequence of standard commands you type on the command line. Once you know the commands, creating a script is nothing more than copying and pasting them into a text file.

Step 2) Add input parsing. How do you read a file to get the user names? Add it to your script and wrap your above commands inside a loop over these user names.

Step 3) Add error checking. How do you check if a user already exists? Add it to your script.

If you run into a problem, ask, but it needs to be a specific problem, not the entire assignment verbatim.
 
1 members found this post helpful.
  


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
Script to Auto-add Domain Users to Workstation Power Users Group doesn't work avinash.rao Ubuntu 0 08-22-2009 04:57 AM
Script to add a secondary group to all users except system default users Tekken Linux - Server 5 06-29-2009 04:02 PM
Correct output from script appears only when script is run interactively kaplan71 Linux - Software 2 01-15-2009 11:47 AM
how to write crontab for cpp program so that it accepts input interactively srinivas445 Linux - Newbie 1 10-15-2008 01:09 PM
NTPD - add to rc.local or write a script downinthemine Linux - Software 0 04-21-2004 09:52 AM

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

All times are GMT -5. The time now is 11:29 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