Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

for-loop for creating users in linux

Posted on 2007-12-07
4
Medium Priority
?
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 2000 total points
ID: 20426803
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
ID: 20426929
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
ID: 20426952
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
ID: 20426960
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:
Suggested Courses

604 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