Solved

Rsync problems

Posted on 2010-08-19
8
915 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
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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
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…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…

830 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