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:
#!/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.
#!/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.
Check your quotes.
Try this:
Change
rsh $SERVER '/usr/sbin/useradd -g dbagroup $line'
rsh $SERVER 'echo $line"123" | passwd --stdin "$line"'
to
rsh $SERVER "/usr/sbin/useradd -g dbagroup $line"
rsh $SERVER "echo ${line}123 | passwd --stdin $line"
You could also try
rsh $SERVER "/usr/sbin/useradd -g dbagroup -p $(openssl passwd ${line}123) $line"
Hello
Chubler_XL and DexDex200
I really appreciate your help,
well after modify my script with the suggestions you made I get this:
#!/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....
./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.
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