Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding new user, using unix, linux scripts, please help 1

Status
Not open for further replies.

tdang2

Programmer
Jun 4, 2002
8
US
Hello all, I am taking unix and linux classes now and I have a problem with adding a new user by using unix and linux scripts. please help me with the script that adding a new user.
here are the requirements:
1. edit the passwd and shadow files to define the user's account.
2. set an initial password.
3. create the user's home directory.
thanks in advance.
Jon,
 
thanks Ed, I still confuse about those scripts cauze they are not exactly what I am looking for.
 
No one will do your work, you should at least be able to take that thread and figure it out otherwise drop your class now, post some of your code and people will offer help
 
olded - you rock.

Not just giving a handout but instead giving a lesson. We need to all look for teaching opportunities instead of creating more Welfare cases.

Can you imagine when tdang2 tries to get a job and he doesn't really know how to set up a user? The world doesn't need more clueless system admins. You get a star for making the world a better place (even if it is only a small way). Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Einstein:

Thank you for the kind words. You've definitely made my day!

Regards,


Ed
 
well, it's my bad, I should have try before asking for help. anyway, here is what I came up with and please help me at your will.

#/usr/dt/bin/dtksh
echo "useradd was invoked with the following arguments:"
echo ${@}
#useradd dang
dang:passwd:105:20:Tuan:/home/dang:/bin/dtksh
dang::105:dang
mkdir /home/dang
chown dang.dang /home/dang
#passwd <tdang2>
 
Jon:

First, your shell invocation needs work:

#/usr/dt/bin/dtksh

should be:

#!/usr/dt/bin/dtksh

Second, I'm not following what you're trying to do. useradd is an external unix command requiring certain command line arguments. Here's the beginning of the solaris 7 useradd man page:

useradd - administer a new user login on the system

SYNOPSIS
useradd [ -c comment ] [ -d dir ] [ -e expire ]
[ -f inactive ] [ -g group ] [ -G group [, group...]]
[ -m [ -k skel_dir ]]
[ -u uid [ -o]] [ -s shell ] login


My link is a shell script which populates the required arguments.

Third, I don't see why you create the home directory, since if you declare the home directory, the useradd command will create it.

Regards,


Ed


 
Thanks for the help, Ed. I really appreaciate that. I also have a question about your script, do I need to add anything else with your script, like in b/w those brackets?
 
Jon:

Sorry, but I don't understand your question. This thread has no script. If you're referring to my useradd definition above, that's just an excerpt from the man pages.

Regards,

Ed
 
Hello Ed, I have some questions regarding to the script that you posted in your link:
where are all these variables ($dop, $sop, $kop etc) set?
what do they mean?
 
Jon:

These variables are set by command line arguments in the getopts while loop at the beginning of the script. These options are clearly documented in the loop, but
dop is the directory option to useradd and kop is the skeleton directory option.

You may not understand the getopts parse utility. The following loop understands -d and -k options. Suppose this code snippet is in script test.ss:

while getopts d:k: opts
do
case $opts in
d) # set the HOME directory
dop=$OPTARG # Directory OPtion set
;;
k) # skeleton directory option
kop=$OPTARG
;;
esac
done

echo $dop
echo $kop
# end code


If you execute:

test.ss -d dir -k kir

$dop is dir
$kop is kir

Regards,


Ed
 
hi thanks Ed, could u help me with the other two posts? thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top