Solved

for-loop for creating users in linux

Posted on 2007-12-07
4
246 Views
Last Modified: 2013-12-16
Dear Sir/Madam:

i have to create many users in the linux hence thought of using the for-loop but getting the following error :

# for USER in u1 u2 u3 u4 u5 do useradd $USER echo password | passwd --stdin $USER done

syntax error near unexpected token "|"

for ex:
for your reference i used the special character  |
the one which use for the commands like
getsebool -a | grep ftp





0
Comment
Question by:D_wathi
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
Comment Utility
The script below should work

for USER in u1 u2 u3 u4 u5
do
    useradd $USER
    echo password | passwd --stdin $USER
done

If this script does not work, then please post your script

0
 

Author Comment

by:D_wathi
Comment Utility
Sir thanks for the reply , following is the error iam getting

[root@parrot ~]# for USER in u1 u2 u3 u4 u5 do useradd $USER echo password | passwd --stdin $USER done
bash: syntax error near unexpected token `|'
[root@parrot ~]#
0
 

Author Comment

by:D_wathi
Comment Utility
i got it now i did exactly as per the format
[root@parrot ~]# for USER in u1 u2 u3 u4 u5
> do
>    useradd $USER
>    echo password | passwd --stdin $USER
> done
Changing password for user u1.
passwd: all authentication tokens updated successfully.
Changing password for user u2.
passwd: all authentication tokens updated successfully.
Changing password for user u3.
passwd: all authentication tokens updated successfully.
Changing password for user u4.
passwd: all authentication tokens updated successfully.
Changing password for user u5.
passwd: all authentication tokens updated successfully.

thanks for the support

0
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
Are you running the for loop as one line?

try

for USER in u1 u2 u3 u4 u5 ; do ; useradd $USER ; echo password | passwd --stdin $USER ; done
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now