LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-03-2008, 06:08 PM   #1
aapanju
LQ Newbie
 
Registered: Mar 2008
Posts: 26

Rep: Reputation: 15
Adduser Script Not Working .. Can Any 1 Tell Me Why?


#!/bin/bash

i=$1
a=$3001

while (( i=001 ; i<= 400 = user ;a= 3001 ; a <= 3400 ; = UID))
do
echo useradd -p "123" -m -f 28 -G 9999 -u $a user{$i}

Done
 
Old 03-03-2008, 06:18 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by aapanju View Post
#!/bin/bash

i=$1
a=$3001

while (( i=001 ; i<= 400 = user ;a= 3001 ; a <= 3400 ; = UID))
do
echo useradd -p "123" -m -f 28 -G 9999 -u $a user{$i}

Done
2 things.

1. You should make all posts on the same subject in the same thread
2. No offense, but this script is so horribly wrong, it's kindof difficult to tell you what exactly is wrong... it's all wrong. Take a look here: http://tldp.org/LDP/abs/html/loops1.html#EX25

edit: ok, to give you a little pointer, take a look at this:
Code:
#!/bin/bash

i=1
a=3001

while [ "$i" -lt 400 ]
  do 
  echo $i $a
  i=$(($i+1))
  a=$(($a+1))
done
exit
Maybe that helps?

Last edited by BrianK; 03-03-2008 at 06:24 PM.
 
Old 03-03-2008, 06:23 PM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I see numerous problems. I think it will be better if you tell us what the script is supposed to do.

For example, what did you intend with these two lines??:

Quote:
a=$3001

while (( i=001 ; i<= 400 = user ;a= 3001 ; a <= 3400 ; = UID))
 
Old 03-03-2008, 06:26 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
I see from your other post that this is homework. You probably should post back after looking at the link BrianK gave you
 
Old 03-03-2008, 06:34 PM   #5
aapanju
LQ Newbie
 
Registered: Mar 2008
Posts: 26

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by pixellany View Post
I see from your other post that this is homework. You probably should post back after looking at the link BrianK gave you
yes it is homework and apparently no one in my entire class knows how to do it. Right now im the only one in class sitting back to try an figure it out as I have to submit it tommorow.I read all the posts but have no clue how to write this script and have been tryin to google for the last 2 hours. The prof said its like a 6-9 line script an I think that isnt true. Can any one post an adduser script?
 
Old 03-03-2008, 06:51 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
If you don't respond to help already given, you are not going to get very far here. Did you look at the link BrianK gave you?
Can you answer my earlier questions?

What text do you use for BASH scripting?
 
Old 03-03-2008, 06:51 PM   #7
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by aapanju View Post
yes it is homework and apparently no one in my entire class knows how to do it. Right now im the only one in class sitting back to try an figure it out as I have to submit it tommorow.I read all the posts but have no clue how to write this script and have been tryin to google for the last 2 hours. The prof said its like a 6-9 line script an I think that isnt true. Can any one post an adduser script?
See my code snippet above. it echos out the user name & gid that you're looking for.

simply replace

echo $i $a

with

useradd -u $i ....and so on.

from the man pages:
Code:
       useradd [-c comment] [-d home_dir]
               [-e expire_date] [-f inactive_time]
               [-g initial_group] [-G group[,...]]
               [-m [-k skeleton_dir] | -M] [-n] [-o] [-p passwd] [-r]
               [-s shell] [-u uid] login

Last edited by BrianK; 03-03-2008 at 06:53 PM.
 
Old 03-03-2008, 07:09 PM   #8
aapanju
LQ Newbie
 
Registered: Mar 2008
Posts: 26

Original Poster
Rep: Reputation: 15
Its amusing how its so easy for you guys an for me I hardly know what im doing but BrianK I cam eup with this ....

#!/bin/bash

i=1
a=3001

while [ "$i" -lt 400 ]
do
useradd -u $i -p "123" -m -f28 -G 9999 $a
echo $i $a
i=$(($i+1))
a=$(($a+1))
done
exit
 
Old 03-03-2008, 07:10 PM   #9
aapanju
LQ Newbie
 
Registered: Mar 2008
Posts: 26

Original Poster
Rep: Reputation: 15
oh yeah an dere is anoder problem also user name has to have 001 all the way to 400... an I think this will give me 1 to 399... not 400 but thats ok because I can create the 400th manually...
 
Old 03-03-2008, 07:12 PM   #10
aapanju
LQ Newbie
 
Registered: Mar 2008
Posts: 26

Original Poster
Rep: Reputation: 15
do any of you use MSN ? it would make it faster for me .. an easier to talk .. because Iv realised Ill be needing Yall ALOT !
 
Old 03-03-2008, 07:13 PM   #11
aapanju
LQ Newbie
 
Registered: Mar 2008
Posts: 26

Original Poster
Rep: Reputation: 15
Hey brianK its late here I have to leave from college so Ill be back from Home now ,, an try an do the script so i wont reply till I get home. Thanks alot you guys !
 
Old 03-03-2008, 07:54 PM   #12
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by aapanju View Post
Its amusing how its so easy for you guys an for me I hardly know what im doing but BrianK I cam eup with this ....

#!/bin/bash

i=1
a=3001

while [ "$i" -lt 400 ]
do
useradd -u $i -p "123" -m -f28 -G 9999 $a
echo $i $a
i=$(($i+1))
a=$(($a+1))
done
exit
hey hey! progress. I don't know why you're using -m? and why are you passing 9999 to -G? I thought $a was for the group?

also, other than confirmation, there's no reason to echo out $i & $a, though leaving it in there for the time being can help you see what's going on.

All this said, I don't remember the initial problem from the other thread, and, to be honest, don't feel like tracking it down, so either repost it here, or let's all continue over there. your choice.
 
Old 03-03-2008, 11:02 PM   #13
aapanju
LQ Newbie
 
Registered: Mar 2008
Posts: 26

Original Poster
Rep: Reputation: 15
here is what i needed ,, what i wrote in the previous post....
I need a script to create 400 users with username starting from 001 all the way to 400 like user001 all the way to user400. They have to have UID 3001 to 3400 and all shud be in GID 9999. home directories should be /home/user001 all the way to /home/user400 and have a password expiery of 28 days. I am passign 9999 to G because all the users have to be assigned ot the group 9999. The m I suppose is to make a home directory for the user? $a is the UID not group....
 
Old 03-03-2008, 11:03 PM   #14
aapanju
LQ Newbie
 
Registered: Mar 2008
Posts: 26

Original Poster
Rep: Reputation: 15
if i want every user to be added with a home directory should i be using -d and not -m?
 
Old 03-04-2008, 05:19 AM   #15
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,329

Rep: Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364Reputation: 2364
If you read the manpage, it says -d is to NAME the home dir, but you need -m to ensure it will be CREATED if it doesn't already exist.

HTH
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
adduser shell script having some problems. cramer Programming 2 06-10-2006 09:23 PM
Adduser script wincrk Linux - General 1 05-14-2006 11:19 PM
adduser and smbpasswd script homey Linux - Networking 7 09-16-2004 06:01 PM
adduser script problem svs Programming 1 07-31-2001 02:22 PM
Adduser script Copenhagen Cowboy Programming 0 03-06-2001 09:35 AM


All times are GMT -5. The time now is 10:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration