Couple of thoughts. Once you find that a department doesn't exist and create the directory for, it you may wish to create a group for it with 'groupadd'. Then set the GID to the newly created group.
A similar situation should be done for the user directory although you should create the directory with 'useradd'. 'useradd -g GROUP' will make sure the directory has the correct GID. Use the '-K UMASK=026' to make sure newly created files have the correct permissions. You'll have to look up how UMASK works. In this environment you may prefer 027 for more security.
A better way to handle the departments would be to create a list of valid existing departments. It would reduce spelling errors. The last option in the list could be "(N)ew department".
Output Example:
Sorry but I had to use KSH as BASH has a bug with pipes and while loops spawning subprocesses. BASH can't see what happened in the loop after the loop.
Lastly I'd add a check for the user ID at the beginning of your script.
Only people with root access should be able to run any of this.
Lastly I'd add a check for the user ID at the beginning of your script.
Only people with root access should be able to run any of this.[/QUOTE]
thanks i actually did this a couple of nights ago before i looked back at this thread.
as far as the departments go. as far as i know this script (unless my instructor takes it and uses it for future classes) is only going to be used by me for this one class. thank you for your help and direction.
now i do have another question though.
i have read on another forum for using a script to check if a user exists or not and this is what i have found:
$ egrep -i "^username" /etc/passwd
this is how i have it in my script:
/bin/egrep -i $UserName /etc/passwd
if [ $? -eq 0 ]
then
echo "User $UserName exists in /etc/passwd!"
else
echo "User $UserName does not exist in /etc/passwd!"
useradd -u 2000 $UserName
fi
my question is how do i get the little up arrow in the ("^username") to appear in vi editor?
I don't understand your question about the carat character. '^' can be inserted like any other character. In VI you hit 'i' to insert and then <shift 6> on a US keyboard.
I added ':' character to the end of the match to make sure it is an exact match. For instance "^Joe" can match "Joe", "Joe2", or "Joe_38933". "^Joe:" will only match user "Joe".
I don't understand your question about the carat character. '^' can be inserted like any other character. In VI you hit 'i' to insert and then <shift 6> on a US keyboard.
Thank you that is what i was looking for (the keyboard shortcut). man have i had a long day it was only after you said <shift 6> that i saw the character there on the keyboard when i looked for it before posting to this site. man i feel so dumb at the moment haha.
Quote:
Originally Posted by m1xram
I added ':' character to the end of the match to make sure it is an exact match. For instance "^Joe" can match "Joe", "Joe2", or "Joe_38933". "^Joe:" will only match user "Joe".
thank you i will do this as you said.
again thank you for your assistance!
---------- Post updated 03-31-11 at 11:43 AM ---------- Previous update was 03-30-11 at 08:54 PM ----------
my next problem is to create a counter for the UID when i add a user this is what i have currently without the counter
/bin/egerp -i "^$UserName:" /etc/passwrd
if [ $? -eq 0 ]
then
echo "User $UserName exists in /etc/passwd!"
else
echo "User $UserName does not exist in /etc/passwd!"
useradd -u 2000 $UserName
now what i am thinking is something along the lines of this:
/bin/egerp -i "^$UserName:" /etc/passwrd
if [ $? -eq 0 ]
then
echo "User $UserName exists in /etc/passwd!"
else
echo "User $UserName does not exist in /etc/passwd!"
userid=2000
while test $userid -le 3000
do
echo $userid
userid="expr $userid+1"
done
useradd -u $userid $UserName
'useradd' takes care of all that. It will also add the default directory and files in the new home directory and add the appropriate entries into /etc/passwd and /etc/shadow. No need for a counter. See previous comments for more information.
If you have to use a counter, these constructs will work also.
But, then you'll have to find the highest UID and GID values in /etc/passwd for regular users. That will involve reading /etc/login.defs to get UID_MIN, UID_MAX, GID_MIN, GID_MAX and reading all of /etc/passwd for maximum valid UID and GID values. It's just not worth it. 'useradd' is much easier. To create password run 'passwd $user' after 'useradd'. So that's...
I have a script, which is checking if file exists and move it to another directory
if
then
mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly
mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly
... (9 Replies)
Hello All,
I have to write a shell script and use it in informatica. The script has to perform below actions:
The script gets executed from edw user.
Through the script, a DT folder has to be created under edw_sca user.
Is this scenario possible through a SHELL script or not.
... (2 Replies)
Hi All,
I am trying to uninstall jdk 1.5 from my Solaris 10 64 bit but some how was not successful.so tried to delete the folder of jdk from /usr but its throughing error as:
Unable to remove directory jdk: Read-only file system
Even I tried to create a dir in /usr but its not allowing me... (4 Replies)
Hello,
I am new in AIX please tell how can i create user and add group in this user for example, i want to create user umair and want to add this user primanry group DBA and secondary group ORACLE,how can i do this please tell in detail
Thanks,
Umair (1 Reply)
Hi All,
I have directory under /opt/test.
The ownership of the test directory is root:root.
I have login to the server as test user.
I need to have some script to create a directory inside /opt/test.
This script will be called as test user.
When I try to execute... (4 Replies)
hello.
i hav accepted name of directory from user through a form.now i need to create a directory under cgi-bin of that name.I am not able to do so.n help is required (12 Replies)
Please help. I am the beginner. Don't understand about archive file. How to create a directory for the files from each archive with name of directory which equivalent to the base name of the archive. eg I have file abc.txt. How can I create a directory name abc. Thank you (1 Reply)
Hi, Im newbie,
I wanna to create file in each user directory, how to make that script, maybe someone can give me example, im confusing coz i have to change form one user directory to other
Thank U. (8 Replies)