LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-07-2008, 06:27 AM   #1
just_me_then
Member
 
Registered: Dec 2006
Posts: 59

Rep: Reputation: 15
scp in bash script only getting to 11%


Hello,

I have a very simple bash script (bottom of post), which creates a database dump, and sends it using scp to a separate host.

It creates the dump successfully, but the scp only ever gets to 11%. (output bellow).

Quote:
[user@host ~]$ ./play.sh
===============
spawn scp 07042008.out root@host:/Volumes/d1/Backups/
Password:
07042008.out 11% 171MB 17.1MB/s 01:16 ETA

File size of the dump is about 1.5GB. There is nothing in any logs which seems related.
Can any one suggest what i might be doing wrong? (im fairly new to writing bash scripts!).

Many Thanks!



SCRIPT:
Quote:
#!/bin/bash
HOST="host"
USER="user"
PASS="password"

pg_dumpall > $(date +%d%m%Y".out")

VAR=$(expect -c "
spawn scp $(date +%d%m%Y".out") $USER@$HOST:/Volumes/d1/Backups/
expect \"password:\"
send \"$PASS\r\"
expect \"\\\\$\"
")

echo "==============="
echo "$VAR"
 
Old 04-07-2008, 07:07 AM   #2
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 489

Rep: Reputation: 37
Why not use SSH Certification for this.
My earlier working setup goes as below:

Code:
1. The basis of using ssh without typing your password is public key based authentication. You need to generate a pair of public/private keys for this. We shall stick to version 2 of ssh. 

2. Firstly, generate your public/private keys using ssh-keygen 

% ssh-keygen -t rsa 

Must use the -t option to specify that you are producing keys for SSHv2 using RSA. This will generate your id_rsa and id_rsa.pub in the .ssh directory in your home directory. I strongly suggest using a passphrase. 

3. Now copy the id_rsa.pub to the .ssh directory of the remote host you want to logon to as authorized_keys2. 
[Note: If you have more than one host from which you want to connect to the remote host, you need to add the local host's id_rsa.pub as one line in the authorized_keys2 file of the remote host, i.e., you can have more than one entry. Also, you need to 'chmod 644 authorized_keys2' to make it unwritable to everybody apart from the user. It is best to have .ssh and associated directories on the server machine to have at most 0600 permissions. ] 
You are basically telling the sshd daemon on the remote machine to encrypt the connection with this public key and that this key is authorized for version 2 of the ssh protocol. 

% scp ~root/.ssh/id_rsa.pub root@server-ip:~root/.ssh/authorized_keys2
After this what you have to do is just create a script with scp commands to transfers files & let us know if still that problem persists.

Thanks goes to author from where I took the above tutorial and all who suggested me to use SSH instead of expect in this forum.
 
Old 04-07-2008, 07:13 AM   #3
just_me_then
Member
 
Registered: Dec 2006
Posts: 59

Original Poster
Rep: Reputation: 15
Thanks. Ill give that a go. Not sure it will solve the problem though, and the expect is working at the moment?

Thanks!
 
Old 04-07-2008, 07:20 AM   #4
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,962

Rep: Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341Reputation: 1341
Can you scp the backup file, from CLI? You can use the -v option to make scp more verbose.

Regards
 
Old 04-07-2008, 07:28 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
I second the use of public key authentication. Using expect to "type in" passwords for you is useful in some cases (e.g. test automation) but shouldn't be used for day-to-day authentication if it can be avoided.

With regards to the scp command not working... try to reduce the complexity. Does it work if you do it maunally - starting the scp command from an interactive shell and typing in the password yourself?

Assuming it still fails from an interactive shell, the first thing which springs to mind is that the destination filesystem does not have enough space. Did you check that?
 
Old 04-27-2008, 04:02 AM   #6
tanveer
Member
 
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 489

Rep: Reputation: 37
PHP Code:
If an expect pattern is  the keyword timeoutthe corresponding body is executed upon timeout.  If no timeout keyword is usedan implicit null action is executed upon timeout

The default timeout period for expect is 10 seconds but may be set, for example to 30by the command “set timeout 30”.  Timeout is an expect global. 

An infinite timeout may be designated by the value -1. 
This could be also the reason behind this.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script problems: scp/ssh from the node of a cluster to the other server frankie_DJ Programming 2 01-27-2007 07:29 PM
crontab over scp on bash jason.farmer Linux - General 1 09-23-2006 11:50 AM
setting up scp alias under bash - parameter passing problem gjr Linux - Newbie 4 06-08-2005 07:38 AM
NFS or SCP in a script rooch84 Linux - Software 7 09-01-2004 11:50 AM
using scp in a script jeempc Programming 2 08-15-2004 10:47 AM


All times are GMT -5. The time now is 07:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration