Welcome to the Linux Foundation Forum!

Adding multiple users and setting vnc passwords?

Options
emacsx
emacsx Posts: 3
edited February 2016 in Command Line/Scripting

I can add users using the following commands without specifying a group

# useradd USER1

# passwd USER1

password: ******

Retype password:

password: ******

but if I use the following script with a text file (user_list.txt) containing list of user, i.e. one user per line and user name and password separated by a space, will that work? Am I missing something in the script?

=======================

#!/bin/bash

NEW_USERS="/tmp/scripts/user_list.txt"

HOME_BASE="/home/"

cat ${NEW_USERS} | \

while read USER PASSWORD

do

useradd -p ${PASSWORD} -m -d ${HOME_BASE}${USER} ${USER}

done

=======================

user_list.txt content:

=======================

USER1 USER1_PASSWORD

USER2 USER2_PASSWORD

USER3 USER3_PASSWORD

...

USER9 USER9_PASSWORD

=======================

For the same users I have to set the vnc password for each user manually using the following commands

# su - USER1

$ vncpasswd

password: ******

Retype password: ******

$ exit

How can I write a script to read the same text file and set vnc passwords?

BTW I am using Red Hat Linux 5.

Categories

Upcoming Training