Sponsored Content
Full Discussion: Automatic User Creation
Top Forums Shell Programming and Scripting Automatic User Creation Post 302752321 by charlieabee on Sunday 6th of January 2013 08:17:30 PM
Old 01-06-2013
gahh I'm confused. I was under the impression that I was incrementing the value which then dictates which line to read from the file.

the code you've said I should use, could you possibly help me in terms of what I need to replace if I put that in and where etc?

Sorry I'm just so new to shell scripting, total noob.

---------- Post updated at 08:17 PM ---------- Previous update was at 07:09 PM ----------

I have managed to integrate your suggestion Jerry thanks a lot for the help but it's brought up another issue now, maybe simply fixed but I can't get my head around it.

This is my code now:
Quote:
useradd () {

while read eachline
do
existinguser=$(find /home -name $eachline)
if
[ -s $existinguser ]
then
sudo useradd -m $eachline
else
userexists

fi
done < Usernames


}

userexists () {
echo "PRESS 1 TO DELETE THE OLD $existinguser ACCOUNT, OR 2 TO KEEP IT, BUT RENAME IT WITH _OLD PREFIX:"
read input
echo $input

if [ $input -eq '1' ]
then
user=$(basename $existinguser)
sudo userdel $user
sudo rm -rf $existinguser
echo "USER ACCOUNT DELETED"
sudo useradd -m $user
unset username
unset existinguser
unset user
elif [ $input -eq '2' ]
then
suffix="_old"
user=$(basename $existinguser)
sudo userdel $user
sudo mv /home/$user /home/$user$suffix
echo "USER ACCOUNT NAME SUFFIXED WITH _OLD"
sudo useradd -m $user
unset username
unset existinguser
unset user
fi

useradd

}

useradd
The script successfully creates user accounts for names of accounts that don't already exist but when the userexists () function is called it throws up an infinite loop error message that says,
Quote:
./makeUser1: 28: [: /home/shaun: unexpected operator
PRESS 1 TO DELETE THE OLD /home/shaun
/home/charlie/.local/share/Trash/files/shaun ACCOUNT, OR 2 TO KEEP IT, BUT RENAME IT WITH _OLD PREFIX:
ellis
./makeUser1: 45: [: Illegal number: ellis
./makeUser1: 55: [: Illegal number: ellis
If anybody can help me fix this issue it would be much appreciated!

thank's in advance again
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

user creation problem

hello, Actually I want to create a user for our brower based custom application for the mail access from our mailserver(linux). I create user dummy and I granted all the privileages to dummy user and made dummy equivelent to root and if I tried to create a another user logging as dummy ... (1 Reply)
Discussion started by: jarkvarma
1 Replies

2. UNIX for Advanced & Expert Users

Automatic time out of user login

I have asked by our security team to implement an automatic time out for user logins after a specified time interval. I have never heard of this feature in Unix before. Does anyone know of a way to accomplish this for HP-UX 11i? (2 Replies)
Discussion started by: keelba
2 Replies

3. Solaris

User creation

Hi all, I want to create one user with full permissions to one directory called /opt/tivoli/tsm/client/ba/bin. Name for the user Tivoli Thanks & Regards Babu (7 Replies)
Discussion started by: lbreddy
7 Replies

4. Solaris

User Creation

i am trying to create a user on solaris 10. it is not taking user name with more than ten characters. which file i need to edit to do this setting. (4 Replies)
Discussion started by: raynu.sharma
4 Replies

5. Red Hat

User creation

Hi Thanks in advance. How to create a user without useradd command ?? (1 Reply)
Discussion started by: krish4linux
1 Replies

6. Solaris

Need help with user creation

Hello guys, i have a problem where i cant create a user and here some problem that i encounter. 1. /etc/passwd seems locked. 2. getting this error UX: useradd: ERROR: Cannot update system files - login cannot be created. # useradd -u 47367 -g 1084 -c "user123" -d /local/home/user123 -s... (2 Replies)
Discussion started by: brew
2 Replies

7. AIX

User creation

hi seniors i want to create the users like when the user try to login it should not should not promt for passwd is it possible to create users like this please help me (6 Replies)
Discussion started by: senmak
6 Replies

8. Shell Programming and Scripting

User creation script

Hi Gems.. I am working out on project of creating a mass user on 100 server. Please help me with script where i can create an user id of new 80 user using shell script Thanks in advance. Indrajit Bhagat (1 Reply)
Discussion started by: indrajit_renu
1 Replies

9. Solaris

NIS user creation

Hi can anyone help me how to create a NIS user by editing the files like Passwd,group, Netgroup,auto.home and Aliases using the "enis" utility? Please do the needful................................ (4 Replies)
Discussion started by: Revathi@1
4 Replies
script(1)							   User Commands							 script(1)

NAME
script - make record of a terminal session SYNOPSIS
script [-a] [filename] DESCRIPTION
The script utility makes a record of everything printed on your screen. The record is written to filename. If no file name is given, the record is saved in the file typescript. See WARNINGS. The script command forks and creates a sub-shell, according to the value of $SHELL, and records the text from this session. The script ends when the forked shell exits or when Control-d is typed. OPTIONS
The following option is supported: -a Appends the session record to filename, rather than overwriting it. NOTES
script places everything that appears on the screen in filename, including prompts. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) WARNINGS
script can pose a security risk when used in directories that are writable by other users (for example, /tmp), especially when run by a privileged user, that is, root. Be sure that typescript is not a link before running script. SunOS 5.10 30 Jan 2004 script(1)
All times are GMT -4. The time now is 06:10 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy