LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-07-2016, 12:52 PM   #1
James0806
Member
 
Registered: Jul 2014
Posts: 41

Rep: Reputation: Disabled
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

Last edited by James0806; 04-07-2016 at 12:53 PM.
 
Old 04-08-2016, 05:31 AM   #2
tshikose
Member
 
Registered: Apr 2010
Location: Kinshasa, Democratic Republic of Congo
Distribution: RHEL, Fedora, CentOS
Posts: 525

Rep: Reputation: 95
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.

Last edited by tshikose; 04-08-2016 at 05:33 AM.
 
1 members found this post helpful.
Old 04-08-2016, 09:19 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by James0806 View Post
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????
 
Old 04-11-2016, 06:10 PM   #4
James0806
Member
 
Registered: Jul 2014
Posts: 41

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


Reply

Tags
shell scripting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script for adding multiple users on multiple servers. newtech Linux - Newbie 3 04-07-2015 03:58 AM
Need help in creating a script which will change password of user on multiple servers linux_neophyte Linux - Newbie 5 09-07-2013 03:04 AM
Need help in creating a script which will change password of user on multiple server linux_neophyte Programming 5 09-06-2013 05:05 AM
Setting password for users in a shell script?? krishvij Linux - Newbie 3 03-10-2005 09:17 AM
script for creating multiple users d3funct Programming 1 08-21-2001 05:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration