-   Linux - General (
-   -   scp in bash script only getting to 11% (

just_me_then 04-07-2008 05:27 AM

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"

tanveer 04-07-2008 06:07 AM

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.

just_me_then 04-07-2008 06:13 AM

Thanks. Ill give that a go. Not sure it will solve the problem though, and the expect is working at the moment?


bathory 04-07-2008 06:20 AM

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


matthewg42 04-07-2008 06:28 AM

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?

tanveer 04-27-2008 03:02 AM

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.

All times are GMT -5. The time now is 03:38 PM.