Solved

Rsync problems

Posted on 2010-08-19
8
912 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now