GagA// 0n D nEt

It is currently Sat Dec 15, 2018 9:27 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Shell Script: Scp files automatically without password
PostPosted: Sun Jun 07, 2009 12:34 am 
Offline

Joined: Wed Jul 18, 2007 1:14 am
Posts: 181
The following script can be used to transfer the files from one server to another without having to provide password. However, before you use this script you will have to ensure that the public ssh-keys for the user which will be executing the script are exchanged. In case you aren't aware of how to transfer the public ssh-key for password-less login, please click here.

Here is how the script goes:
Code:
#!/bin/bash

### scp files via key exchange ###

## ~/file_list contains the  list of files which needs to be copied over. ##

for i in `cat ~/file_list`
do
scp $i [email protected]:/~
done;

### End Script ###


Top
 Profile  
 
 Post subject: Re: Shell Script: Scp files automatically without password
PostPosted: Sun Jun 07, 2009 1:04 am 
Offline

Joined: Wed Jul 18, 2007 1:14 am
Posts: 181
The following script is designed using expect utility. Please note that in order to execute this script you will need to have expect utility present on the server.

The following is how the script goes:
Code:
#!/usr/bin/expect -f

# connect via scp
spawn scp /home/gagan/myfile.txt [email protected]:/var/www/html/
#######################
expect {
-re ".*es.*o.*" {
exp_send "yes\r"
exp_continue
}
-re ".*sword.*" {
exp_send "PASSWORD\r"
}
}
interact


Please note that in the above script, you will have to replace PASSWORD, with the password for user on remotehost.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group