Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Rsync problems

Posted on 2010-08-19
8
Medium Priority
?
919 Views
Last Modified: 2013-12-16
Hi,

I have this script to run rsync and avoid prompt passwod.

This is my script:

#!/usr/bin/expect

spawn rsync --progress -av user@server:/var/www/vhosts/ /backups/vhosts/
expect \"*?assword:*\"
send -- "mypass\r"
expect eof

The problem is, when rsync strart download the files, after a minute crash, but if I run the rsync command "rsync --progress -av user@server:/var/www/vhosts/ /backups/vhosts/" out of script is work very well

Can you help me ?

Best regards

André Bolinhas
0
Comment
Question by:abolinhas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 9

Expert Comment

by:jeremycrussell
ID: 33477458
An alternative to this would be to use rsync over ssh, and use a ssh key.  1.  avoid requirement for password, 2. more secure as connection is secured and no password is stored in a script.  3. no need for expect scripting.

i.e. rsync --progress -avz -e "ssh -i /path/to/key/id_dsa" user@server:/path/to/files/ /path/to/files/

I imagine the issue in the script is the 'expect eof' the rsync will send output to both stderr and stdout, so its probably mucking up the last line of the script.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33482795
Could also be a timeout problem.
Try "set timeout nnn" as the first line of your script (above "spawn ...").
Set nnn to a suitable value (in seconds), e.g. 900.
wmp
0
 
LVL 9

Author Comment

by:abolinhas
ID: 33483279
Hi,

@jeremycrussell - How can I do this ? Just generate new public key on remote server and copy the id_dsa.pub to ~/.ssh/ on other server?


@woolmilkporc - Like this ?
#!/usr/bin/expect

set timeout nnn
spawn rsync --progress -av user@server:/var/www/vhosts/ /backups/vhosts/
expect \"*?assword:*\"
send -- "mypass\r"
expect eof
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 2

Expert Comment

by:arunkeerthan
ID: 33483400
generate a public key in the server

# ssh-keygen -t rsa

it will tell you the location where is stores the key. copy that files content  from the server to your local machine /userhome/.ssh/authorized_keys

Then takeout your password storing script from your script file put the rsync commands set command alone and execute the script.

Thanks
arunkeerthan
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 33483462
>> Like this ? <<
Yes. Don't forget to replace nnn with a "real" value.
0
 
LVL 9

Author Comment

by:abolinhas
ID: 33483477
Hi arunkeerthan,

I try this, but not work, still ask me for password.

I have generated the key on remote server and then I copied the id_rsa.pub to ~/.ssh/ on local server.
The I add the id_rsa.pub into authorized_keys file by this command "cat id_rsa.pub >> authorized_keys"

But still don't work.

Best
0
 
LVL 26

Accepted Solution

by:
arober11 earned 2000 total points
ID: 33483705
1) Nope if you already have a key pair on the local server e.g. ~/.ssh/id_rsa  and d_rsa.pub   or   ~/.ssh/id_dsa  and d_dsa.pub  simply transfer the PUBLIC (id_*sa.pub) file to your $HOME directory on the remote server, do a:

mkdir -p $HOME/.ssh
chmod go-w  $HOME
chmod 700  $HOME/.ssh
cat $HOME/id_*sa.pub >> $HOME/.ssh/authorized_keys
chmod 600  authorized_keys

Then on the local server, test the access:

ssh user@remote.ip 'uname -a'

2) On the expect front, change  nnn   to 100000
0
 
LVL 9

Author Closing Comment

by:abolinhas
ID: 33484334
Hi arober11,

This solution solve my problem.
"mkdir -p $HOME/.ssh
chmod go-w  $HOME
chmod 700  $HOME/.ssh
cat $HOME/id_*sa.pub >> $HOME/.ssh/authorized_keys
chmod 600  authorized_keys"

Many thanks for your help.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question