| | |
Bash add user script
Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2007
Posts: 252
Reputation:
Solved Threads: 27
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
any help with this is greatly appreciated.
thanks
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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
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!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
•
•
Join Date: Oct 2007
Posts: 399
Reputation:
Solved Threads: 47
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
Hope it's working soon
, Mike
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)
PATH=$PATH:/usr/sbin:/usr/bin 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!
------------------------------------------------------------------------
The greatest viral marketing idea of all time, get your copy of this Free Report now!
![]() |
Similar Threads
- How to print to file (Perl)
- Creating a user in Linux without adduser/useradd (Shell Scripting)
- Convert shell script for looping (Shell Scripting)
- awk question (Shell Scripting)
- Interpreting a script line by line (Shell Scripting)
- Automated FS usage monitoring (Shell Scripting)
- Shell Scripting problem and related awk issues (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: need help getting pid value
- Next Thread: help in shell scripting
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting





