LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell script for creating multiple users with password (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-for-creating-multiple-users-with-password-4175576931/)

James0806 04-07-2016 12:52 PM

shell script for creating multiple users with password
 
I use shell script to create multiple users with password as their requirement

for i in `cat users`;do useradd -d /u02 -s /usr/libexec/openssh/sftp-server -G ftp-users $i;echo "$i@123" | passwd $i --stdin;done

the above shell script creates users in the file users file

mchang
tcheng
mamri
skumar
kdecianni


the password according that script would be someuser@123
Ex: for for mchang it will be mchang@123
But the requirement is like Mchang@123
how can it be possible

tshikose 04-08-2016 05:31 AM

Hi,

Please check (as I have not tested), test and try the below.

Code:

for UserName in `cat users` ; do useradd -d /u02 -s /usr/libexec/openssh/sftp-server -G ftp-users $UserName ; PassWord=$( echo $( tr '[:lower:]' '[:upper:]' <<< ${UserName:0:1} )${UserName:1} ) ; echo "$PassWord@123" | passwd $UserName --stdin ; done
My personal comment is those are bad passwords as any user can easily deduct others passwords from his.
You might need to force a password change at next login by adding passwd -e $UserName.

TB0ne 04-08-2016 09:19 AM

Quote:

Originally Posted by James0806 (Post 5527723)
I use shell script to create multiple users with password as their requirement
for i in `cat users`;do useradd -d /u02 -s /usr/libexec/openssh/sftp-server -G ftp-users $i;echo "$i@123" | passwd $i --stdin;done

the above shell script creates users in the file users file

mchang
tcheng
mamri
skumar
kdecianni


the password according that script would be someuser@123 Ex: for for mchang it will be mchang@123 But the requirement is like Mchang@123
how can it be possible

You've been asking about such scripts for TWO YEARS NOW:
http://www.linuxquestions.org/questi...ds-4175522587/

Seems odd that in that time, you've not progressed/learned ANYTHING about bash scripting, and re-hash this same question. There are THOUSANDS of examples you can find on Google for how to upper-case a letter in a Linux bash script. You can use sed, tr, or built-in bash functions, like:
Code:

echo "${foo^}"
So...what have you done/tried on your own????

James0806 04-11-2016 06:10 PM

I think PassWord=$(tr '[:lower:]' '[:upper:]' <<< ${UserName:0:1} )${UserName:1} this would be better for assigning to variable


All times are GMT -5. The time now is 07:12 PM.