Create users remotely


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create users remotely
# 1  
Old 02-07-2013
Create users remotely

Hello Forum,

I just wrote a bash script to create users remotely from a file.

When I run the script localy, it work nice.
But when I run it using rsh it stops.

My script is:

Code:
#!/bin/bash
1|cat /root/usuarios.txt | while read line; do
2|       /usr/sbin/adduser $line
3|       echo $line"123" | passwd --stdin "$line"
4|       echo; echo "User $line's password changed!!"
5|done

1, read a file | and while read each line do
2, run adduser command for each $line variable content
3, run echo for the content of $Line variable + 123 and sent it to standar input of passwd command when ask for the username ($Line variable content)
4, and finally show a Message, "User's password changed"

If I run localy it works perfect.
When I put it together with rsh it fails.


Code:
#!/bin/bash
clear
. /root/serv.txt               #file with IP Addresses

for ((i=1;i<=2;i+=1));       #I'm testing with only 2 servers  in the serv.txt file
do
        SERVER=`expr ${SERVIDOR[$i]}`
        echo "----------------   $SERVER   -----------------"

                cat /root/usuarios.txt | while read line; do
                        rsh $SERVER '/usr/sbin/useradd -g dbagroup $line'
                        rsh $SERVER 'echo $line"123" | passwd --stdin "$line"'
                done
echo ""
done


I really appreciate your help if you can help me to fix this bad script definition.

Last edited by Scrutinizer; 02-08-2013 at 12:23 PM.. Reason: quote tags -> code tags
# 2  
Old 02-07-2013
Check your quotes.

Try this:


Change

Code:
rsh $SERVER '/usr/sbin/useradd -g dbagroup $line'
rsh $SERVER 'echo $line"123" | passwd --stdin "$line"'

to

Code:
rsh $SERVER "/usr/sbin/useradd -g dbagroup $line"
rsh $SERVER "echo ${line}123 | passwd --stdin $line"

# 3  
Old 02-07-2013
You could also try

Code:
rsh $SERVER "/usr/sbin/useradd -g dbagroup -p $(openssl passwd ${line}123) $line"

# 4  
Old 02-08-2013
Hello
Chubler_XL and DexDex200

I really appreciate your help,
well after modify my script with the suggestions you made I get this:

Code:
#!/bin/bash
clear
./root/SCRIPTS/Hosts/serv.txt

for ((i=1;i<=2;i+=1));
do
SERVER=`expr ${SERVIDOR[$i]}`
echo "---------------- $SERVER -----------------"

cat /root/SCRIPTS/Usuarios/lista.txt | while read line; do
        rsh $SERVER "/usr/sbin/useradd -g dbagroup -p $(openssl passwd ${line}123) $line"
        done
        echo ""
done


I get this message....

Code:
./remote.sh
./remote.sh: line 3: ./root/SCRIPTS/Hosts/serv.txt: No such file or directory
expr: missing operand
Try `expr --help' for more information.
----------------  -----------------
Warning: truncating password to 8 characters
/usr/sbin/useradd -g dbagroup -p l3m3VOfa.mz4w eduardomejia: host unknown
Trying krb4 rlogin...
/usr/sbin/useradd -g dbagroup -p l3m3VOfa.mz4w eduardomejia: host unknown
trying normal rlogin (/usr/bin/rlogin)
/usr/sbin/useradd -g dbagroup -p l3m3VOfa.mz4w eduardomejia: Unknown host
/usr/sbin/useradd -g dbagroup -p Ravebxl8fb.oc yayo: host unknown
Trying krb4 rlogin...
/usr/sbin/useradd -g dbagroup -p Ravebxl8fb.oc yayo: host unknown
trying normal rlogin (/usr/bin/rlogin)
/usr/sbin/useradd -g dbagroup -p Ravebxl8fb.oc yayo: Unknown host

expr: missing operand
Try `expr --help' for more information.
----------------  -----------------
Warning: truncating password to 8 characters


Best Regards.

Last edited by Scrutinizer; 02-08-2013 at 12:24 PM.. Reason: quote tags -> code tags
# 5  
Old 02-08-2013
Did you look at the error message? It cannot find ./root/SCRIPTS/Hosts/serv.txt. So that file does not get loaded,
There should be a space between . and /root
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create summery of al users + date

Hello, I have problem to write script which can collect users "username" and the time that each user has been created in our machine and store these data in file database.txt I have searched a lot and found we can see the exact time we create user with:passwd -S username also list user will... (3 Replies)
Discussion started by: nimafire
3 Replies

2. Shell Programming and Scripting

Create multiple users with individual passwords to users

hi, i am new to shell scripts i write a shell script to create multiple users but i need to give passwords to that users while creating users, command to write this script (1 Reply)
Discussion started by: DONFOX
1 Replies

3. Solaris

Can we create multiple users with same UID?

* Can we create multiple users with same UID? * Can we give root permissions to normal user like admin.s ? If YES give me full details (syntax of sudo/RBAC) (14 Replies)
Discussion started by: Navkreddy
14 Replies

4. Shell Programming and Scripting

Create a list of commands in a central location, and then run them all remotely through a ssh here

I'm trying to write a script that in the end will from one central location hop to a bunch of servers and then run a series of ping tests. The thing is, the list of devices that needs to be pinged is going to be different for each server. So what I want to do is be able to do is read through the... (0 Replies)
Discussion started by: DeCoTwc
0 Replies

5. IP Networking

helping new Linux users remotely ?

I volunteer with a small charity which locally donates refurbished computers to people who normally could not afford their own computer. Most of these computers now have Linux on them. We are in the process of remastering Xubuntu 9.04 to use as our main distro from now on. In the past any time... (3 Replies)
Discussion started by: lagagnon
3 Replies

6. Shell Programming and Scripting

Create new users

Hi , i would like to create a new user over unix ,which are these commands to used and which are the directories to handler? Thank you (3 Replies)
Discussion started by: dimitris
3 Replies

7. Solaris

How to create users in NIS

How to create users in NIS server in solaris Thanks in Advance (6 Replies)
Discussion started by: durgaprasadr13
6 Replies

8. Solaris

Can't create users in /home

Hi Friends,, I installed solaris 10 in vmware just now.I got a simple problem while i want to create users in /home directory.It is saying "cannot create ".So i checked the permission and then i find that the perm to user(root) is r-x.So i tried to change it to rwx using chmod but again i got a... (4 Replies)
Discussion started by: sdspawankumar
4 Replies

9. UNIX Desktop Questions & Answers

How to create users on HP UX????

I new to unix and I'm using a HP UX and I'm logging in as user: root. I wish to create new users by using the 'useradd' command. When I keyed in' useradd -u 101 -g group john', the reply was 'Group group specified with -g does not exist'. I've read the man page on useradd and I still don't... (8 Replies)
Discussion started by: mascotlee
8 Replies

10. Shell Programming and Scripting

create users from template

Create users from template file (0 Replies)
Discussion started by: rijeshpp
0 Replies
Login or Register to Ask a Question