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 |
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 You might need to force a password change at next login by adding passwd -e $UserName. |
Quote:
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^}" |
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. |