Question meaning

1
2
3
4
5
6
7
8
9
10
11
12
13
Unix stores account information in 2 files. These files are the password file /etc/passwd, and the shadow file /etc/shadow. Each user belongs to a group with this information being stored in /etc/group. Refer to the man pages for the purpose and format of these files. To successfully add a user, a line must be added to the password and shadow files. Because of the importance of these files to the systems operation, any production quality script should ensure that they are not corrupted by any circumstances during an update.
Your script MUST take the following arguments:
-P to specify the name of the password file to update.
-S to specify the name of the shadow file to update.
-G to specify the group file to consult.
Such arguments MAY be followed with:
-p to specify the new entry to be added to the password file.
-s to specify the entry to be added to the shadow password file
Do assign the default password for all the users created. This may take a bit more time, but don’t give up, do explore. Good luck!
Do check for errors, for example, if the user name entered already exist, then it should state that “User Exist! Try another Name”. Lastly in some circumstances you will have to make decisions. For example let’s say a home directory is specified that already exists and belongs to another user. What should you do here? This is a design decision – normally you would terminate with an error. What if the home directory does not exist? You would have to create it right? but also ensure the permissions are correct…All directories should be under /home – this is the norm.
In other words think about what could go wrong and try to handle it nicely… You should put comments in your code justifying your actions.
To test your files simply examine them and try to log in with a user you created.


can someone just explain to me then i start to implementing?
not really understand the question~
It looks like you are to write a UNIX shell script to handle user accounts on UNIX. Your instructor wants your script to write to the /etc/password (or a file with the same format); /etc/shadow (or a file with the same format); and the /etc/group file (or a file with the same format.)

Your instructor suggests that you should run the "man" command on these files and other UNIX commands to get ideas on how to approach your script.

Your instructor has given you lots of ideas on how to check for errors, and what errors you need to handle.

I hope this helps!
i get what you mean .
but if i code like this
 
useradd chirs

the user will auto add to
/etc/password
/etc/shadow
1
2
3
cat /etc/passwd
//or
cat /etc/shadow

already isn't?
so i not really understand at
your script to write to the /etc/password (or a file with the same format); /etc/shadow (or a file with the same format); and the /etc/group file (or a file with the same format.)

can explain for me?
but if i code like this

useradd chirs

the user will auto add to
/etc/password
/etc/shadow
1
2
3
cat /etc/passwd
//or
cat /etc/shadow


This depends on what your instructor wants you to build. If you are building a new script that does the same job as useradd, then what I described in my first posting still stands.

If your instructor wants you to build a script that calls useradd, then I need to modify my answer.

Can you tell me which way you are supposed to code it?
im using redHat to do it.

which way? i just do in my terminal
example:

1
2
3
4
5
6
7
8
echo "Enter username: "
read username
useradd $username

//when i press useradd $username
//$username will be auto save to
// /etc/passwd
// /etc/shadow file already 


so i don't know what is mean by the
-P to specify the name of the password file to update.
-S to specify the name of the shadow file to update.
-G to specify the group file to consult.

sorry for disturbing again
i think my lecturer just want me do to some basic scripting. just i can't get what her mean.
and now holiday. not able to ask her
Last edited on
Hardcode is bad. It is much more flexible to set options in command line. Then again, repeatedly writing the same, most common options is boring. Hence, a wise default is convenient.

1
2
# foo -P mypw -G mygrp
# foo 

Two calls to "foo". The first gets four options. If "foo" would be your script, then it would use files "mypw" and "mygroup".

The second call would use the default values: "/etc/passwd" and "/etc/group".
The foo is user right?
mypw and mygrp is file name ?

the second call is just use the default value? err
which mean just call the
1
2
# cat /etc/passwd
# cat /etc/group 


isn't?
No. I totally forgot the username parameter from the example. "foo" is the name of a script.

You cannot use "useradd", because it is hardcoded to operate with /etc/{passwd,shadow,group,gshadow}.


IMHO, an exercise that would potentially wreck the authentication files is very very bad. You really should not mess with them and you don't want to make copies either.
yes. i get what you mean. i asked my another friend just now

 
#script1 -P mypwdfile -G mygroupfile 


so if i type this command.
the script1 will run some code and add the user to mypwdfile file right and save to mygroupfile file also ? am i right?
why the link u provide to me.
i read their code.
seem like i never learnt those code.
isn't the only way to do it?
The instructions that you did show clearly state that your script must be able to handle arguments. The linked thread shows an example on how to handle arguments.
Topic archived. No new replies allowed.