Bash add user script

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Bash add user script

 
0
  #1
Feb 21st, 2008
I am attempting to write a script that will add a user to the system. I am using fedora 5 and am attempting to use the useradd: command but i receive "command not found" I am also trying to get the current users from the system so i can check if the user is already there.

any help with this is greatly appreciated.

thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: Bash add user script

 
0
  #2
Feb 22nd, 2008
Hey there,

useradd is probably just not in your path. To safeguard against that error in your script, use a fully qualified path, like:

/usr/bin/useradd - or /usr/sbin/useradd (It's one of those two on Fedora, I believe)

You can check what user already exist on the system by just using awk to pull the usernames from /etc/passwd and then testing against that:

awk -F":" '{print $1}'

then write your script to compare against all those names.

Hope that helps

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 3
Reputation: ionzone is an unknown quantity at this point 
Solved Threads: 0
ionzone ionzone is offline Offline
Newbie Poster

Re: Bash add user script

 
0
  #3
Feb 24th, 2008
Alternatively, you can make a variable
UADD="$(which useradd)"
Then in the script, just put useradd command like this:
$UADD (USERNAME)
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 399
Reputation: eggi will become famous soon enough eggi will become famous soon enough 
Solved Threads: 47
eggi eggi is offline Offline
Posting Whiz

Re: Bash add user script

 
0
  #4
Feb 25th, 2008
Hey there,

The variable is a good idea. Should make your code tighter.

Just be sure that useradd is in your PATH or "which" will give you the same error (not found).

I'm not sure what shell you're using (hence the old-style "export" below) or what your PATH variable resolves to now, but this will probably fix the problem for you if you add it to your .profile, .bashrc or run it off the command line, etc

Shell Scripting Syntax (Toggle Plain Text)
  1. PATH=$PATH:/usr/sbin:/usr/bin
  2. export PATH

Hope it's working soon

, Mike
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 252
Reputation: ProfessorPC is an unknown quantity at this point 
Solved Threads: 27
ProfessorPC ProfessorPC is offline Offline
Posting Whiz in Training

Re: Bash add user script

 
0
  #5
Mar 4th, 2008
thanks for all your help i have completed the script using variables.

thanks again
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC