Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Question about bash, for loop script to repeat on 20 Places

Status
Not open for further replies.

ahmad_abdulghany

Advanced Member level 4
Advanced Member level 4
Joined
Apr 12, 2005
Messages
1,206
Helped
102
Reputation
206
Reaction score
22
Trophy points
1,318
Location
San Jose, California, USA
Visit site
Activity points
11,769
Hi,
I want to automate transferring file to 20 PCs put in the same LAN..

If it wasn't password protected, i was going to write a simple shell script that simply perform the following command on all PCs:

Code:
for i in (1:20)
 do
   sftp user@10.0.0.$i ;
   # Password should be entered here!!
   put $file ;
   exit ;
done

I want to either override password promot, or find a way to pass it automatically to the standard input ..

Can anyone help me please?
Thanks in advance,
Ahmad,
 

Re: Question about bash, for loop script to repeat on 20 Pla

To read things from STDIN from a shell script use the "read" command:
Code:
read password

I'm not sure how to pass that with sftp because the authentication method is interactive.
You might try the "expect" utility. I think that will provide an easier way to do this.
 
Hi Gliss,

Thank you for reply, but i don't know in fact what's the "expect" utility.. Also you said that "read" is used to read "from" STDIN although I want to read "to" STDIN, did i understand it correctly?
Can you give bit more details?

Thank you :)
Ahmad,
 

Re: Question about bash, for loop script to repeat on 20 Pla

Use scp (enable ssh in your 20 PCs)

for each PC:
0. enable sshd
1. generate key RSA:
ssh-keygen -t rsa
2. Copy key public in server
scp ~/.ssh/id_rsa.pub user@host:/home/user/.ssh/authorized_keys2

see: **broken link removed**

now you can copy files without password (use ssh without having to type in your password everytime you use ssh or scp)

enjoy
 
Re: Question about bash, for loop script to repeat on 20 Pla

ghbolivar said:
Use scp (enable ssh in your 20 PCs)

for each PC:
0. enable sshd
1. generate key RSA:
ssh-keygen -t rsa
2. Copy key public in server
scp ~/.ssh/id_rsa.pub user(at)host:/home/user/.ssh/authorized_keys2

see: h**p://www.cs.umd.edu/~arun/misc/ssh.html

now you can copy files without password (use ssh without having to type in your password everytime you use ssh or scp)

enjoy

Thank you i will try it the next time i go to our lab.. But i am worried about its results, did you test it yourself before? :oops:

Also, i feel that it's not secure, isn't it?

Another thing, if you are good at bash scripting, can you suggest a sample script to automatically "put" a "file" to the 20 PC's (that have IPs from 10.0.0.1 to 10.0.0.20 all on the same LAN with the one I'm working on)? Please..

Finally, if you can briefly explain the strange terms in it (e.g. scp, RSA, authorized_key2, etc.) i will be thankfull..

Thanks and regards,
Ahmad,
 

Re: Question about bash, for loop script to repeat on 20 Pla

See

Secure Shell or SSH is a set of standards and an associated network protocol that allows establishing a secure channel between a local and a remote computer. It uses public-key cryptography (RSA for example) to authenticate the remote computer and (optionally) to allow the remote computer to authenticate the user. SSH provides confidentiality and integrity of data exchanged between the two computers using encryption and message authentication codes (MACs).

Secure Copy or SCP is a means of securely transferring computer files between a local and a remote host or between two remote hosts, using the Secure Shell (SSH) protocol.

is very secure!!! ssh and scp

ssh in combination with SCP, as a secure alternative for rcp file transfers—more often used in environments involving Unix!!!

see:
https://en.wikipedia.org/wiki/Secure_Shell, https://en.wikipedia.org/wiki/Secure_copy

A common misconception is that SFTP is simply FTP run over SSH

Finally "ssh-keygen -t rsa" is a command, with option: rsa cryptography


enjoy
20 PC's with linux, WinXp, solaris ????
 
Re: Question about bash, for loop script to repeat on 20 Pla

server : alecto
server's user: test
PC

for each PC :

0. enable sshd (user root)
/etc/init.d/sshd start

1. generate key RSA (user test):
ssh-keygen -t rsa
command ssh-key make directory .ssh in the home of test user

2. Copy key public in server
with test is your user
with alecto is your hostname of server.

scp ~/.ssh/id_rsa.pub test@alecto:/home/test/.ssh/authorized_keys_pc1

witch
pc1 for pc1
pc2 for pc2
.....pc20
*****************************
on server

cat the content of 20 files: authorized_keyspc1+authorized_keyspc2+authorized_keyspc3+... in the /home/test/.ssh/authorized_keys

script
****************************
for i in (1:20)
do
scp file_to_copy test@10.0.0.$i:/home/test
done
*****************************

with file_to_copy is el filename

Finally use ssh without having to type in your password everytime

enjoy

see: h**p://www.cs.umd.edu/~arun/misc/ssh.html
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top