Quick SCP command help

Associate
Joined
19 Jul 2006
Posts
1,847
I want to coppy a backup script from one server to another.

Im running the following as root on server with ip 10.0.6.24
Code:
scp backup 10.0.6.22:/etc/cron.d/
where the file backup is located on server 10.0.6.22 in the etc/cron.d folder.

It askes me for a password which i enter then it says
backup: No such file or directory

what am i doing wrong? as the file is there
 
That command is trying to copy a file named backup in the current directory of the local machine to the remote box. To copy the file from the remote box to the local machine you need to run:

Code:
scp 10.0.6.22:/etc/cron.d/backup .
(assuming you want the file in the current local path)
 
You need to specify the absolute path on the local machine really.

And if you put the local machines public key in the remote machines /root/.ssh/authorized_keys, then it won't ask you for a password.

Alternatively
Code:
echo passw0rd | scp 10.0.6.22:/etc/cron.d/backup /path/to/destination/.
but this would be storing your remote machine's root password as plaintext. :eek:
 
ok new problem.
I have the following script on the server 10.0.6.22
Code:
#/bin/sh
cp -R /home/moodledata /backups/moodledatacopied/
tar -czvf /backups/moodledata/moodledata.tar.gz /backups/moodledatacopied/
mkdir -p /backups/moodledata/moodledata/`/bin/date +%Y/%b`
/bin/mv /backups/moodledata/moodledata.tar.gz /backups/moodledata/moodledata/`/bin/date +%Y/%b/moodledata_%d-%b-%Y.tar.gz`
rm -rvf /backups/moodledatacopied/

This script runs everyday and creates a file with the date at the end.

Now i need to get that file across to my desktop somehow automatically.

Would it be better to put a scp command in that script to send the file to the desktop? i take it id need to specify an account and password somewhere to.

Or would it be better to create a new script on my desktop that scp the file from the server. But then id have to make the script work out the date and find the correct file before scp?
 
Code:
#/bin/sh
cp -R /home/moodledata /backups/moodledatacopied/
tar -czvf /backups/moodledata/moodledata.tar.gz /backups/moodledatacopied/
mkdir -p /backups/moodledata/moodledata/`/bin/date +%Y/%b`
/bin/mv /backups/moodledata/moodledata.tar.gz /backups/moodledata
THE_DATE='/bin/date +%Y/%b/moodledata_%d-%b-%Y'
/moodledata/${THE_DATE}.tar.gz
rm -rvf /backups/moodledatacopied/
scp /moodledata/${THE_DATE}.tar.gz user@hostname:/directory/.

Maybe?
 
Last edited:
ok new problem.
I have the following script on the server 10.0.6.22
Code:
#/bin/sh
cp -R /home/moodledata /backups/moodledatacopied/
tar -czvf /backups/moodledata/moodledata.tar.gz /backups/moodledatacopied/
mkdir -p /backups/moodledata/moodledata/`/bin/date +%Y/%b`
/bin/mv /backups/moodledata/moodledata.tar.gz /backups/moodledata/moodledata/`/bin/date +%Y/%b/moodledata_%d-%b-%Y.tar.gz`
rm -rvf /backups/moodledatacopied/
This script runs everyday and creates a file with the date at the end.

Now i need to get that file across to my desktop somehow automatically.

Would it be better to put a scp command in that script to send the file to the desktop? i take it id need to specify an account and password somewhere to.

Or would it be better to create a new script on my desktop that scp the file from the server. But then id have to make the script work out the date and find the correct file before scp?


I can kind of understand what you are trying to do here, this is what I would probably do. Bear in mind that you will need to have an ssh key with no passphrase set up to do the scp with no password asked.

This isn't following the directory structure you had though, it seemed that you are creating subfolders with no reason when the datestamped filename would do?

Code:
#!/bin/sh

DATE=`/bin/date +%d-%b-%Y`

mkdir -p /backups/moodledatacopied/

cp -R /home/moodledata/* /backups/moodledatacopied/
tar -czvf /backups/moodledata/moodledata.$DATE.tar.gz /backups/moodledatacopied/

rm -rf /backups/moodledatacopied

scp /backups/moodledata/moodledata.$DATE.tar.gz user@hostname:/dir/to/put/it/.
 
Back
Top Bottom