Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


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

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


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).

[user@host ~]$ ./
spawn scp 07042008.out root@host:/Volumes/d1/Backups/
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!


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
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

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

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 in the .ssh directory in your home directory. I strongly suggest using a passphrase. 

3. Now copy the 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 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/ 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
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?

Old 04-07-2008, 07:20 AM   #4
LQ Guru
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,903

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

Old 04-07-2008, 07:28 AM   #5
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
Registered: Feb 2004
Location: e@rth
Distribution: RHEL-3/4/5,Gloria,opensolaris
Posts: 525

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.


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 > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:45 PM.

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