LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Adduser Script Not Working .. Can Any 1 Tell Me Why? (https://www.linuxquestions.org/questions/linux-newbie-8/adduser-script-not-working-can-any-1-tell-me-why-625484/)

aapanju 03-03-2008 06:08 PM

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

BrianK 03-03-2008 06:18 PM

Quote:

Originally Posted by aapanju (Post 3077117)
#!/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?

pixellany 03-03-2008 06:23 PM

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))

pixellany 03-03-2008 06:26 PM

I see from your other post that this is homework. You probably should post back after looking at the link BrianK gave you

aapanju 03-03-2008 06:34 PM

Quote:

Originally Posted by pixellany (Post 3077130)
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?

pixellany 03-03-2008 06:51 PM

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?

BrianK 03-03-2008 06:51 PM

Quote:

Originally Posted by aapanju (Post 3077139)
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


aapanju 03-03-2008 07:09 PM

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

aapanju 03-03-2008 07:10 PM

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...

aapanju 03-03-2008 07:12 PM

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 !

aapanju 03-03-2008 07:13 PM

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 ! :)

BrianK 03-03-2008 07:54 PM

Quote:

Originally Posted by aapanju (Post 3077175)
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.

aapanju 03-03-2008 11:02 PM

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....

aapanju 03-03-2008 11:03 PM

if i want every user to be added with a home directory should i be using -d and not -m?

chrism01 03-04-2008 05:19 AM

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


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