Goutham
asked on
for-loop for creating users in linux
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
[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
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
try
for USER in u1 u2 u3 u4 u5 ; do ; useradd $USER ; echo password | passwd --stdin $USER ; done
ASKER
[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 ~]#