How to run scp command from server on startup script

Asked by ofirst

Hi,
The system - Ubuntu 9.04 updated, with added packages on Pentium 4 (2.8 Ghz).
The problem - how to run "scp" command from a server on startup script.
I have a PC, and exchanged ssh keys with the server (using commands like "ssh-keygen -t rsa " under root user.
I added a package "insserv" (from SUSE systems) to add the script to runlevel 2 3 5 .
When the PC boots, the script runs, but does not copy file from the server .
The same script runs on a "SUSE 10.3" PC, and copies the file from the server to the PC (on boot time).
I tried the commands:
/usr/bin/scp Server-FQDN:/etc/passwd $BackUp_Dir/my-passwd
/usr/bin/scp root@Server-FQDN:/etc/passwd $BackUp_Dir/my-passwd

The script is running, doing some commands, but does not doing this copy.
How should I make the copy run automatically on reboot?

Thanks
Ofir S

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Amarnath
Solved:
Last query:
Last reply:
Revision history for this message
David Santamaría Rogado (howl) said :
#1

You could use /etc/rc.local to run your own commands at startup time.

Revision history for this message
David Santamaría Rogado (howl) said :
#2

You could use /etc/rc.local to run your own commands at startup time.

Revision history for this message
ofirst (ostolovi) said :
#3

Hi,
Thanks for the response; -- it's not working.
The commands in the /etc/rc.local file work, but the "scp" commands don't work.
I put 2 debugging lines before the "scp" commands , with the commands:
id >> /root/Backup/MY_ID
who -r >> /root/Backup/MY_ID
and received (cat /root/Backup/MY_ID) :
root@x-302:~# cat /root/Backup/MY_ID
uid=0(root) gid=0(root)
         run-level 2 Sep 1 15:43 last=

That what i expected - the user was root, and 2 was the run level.
when I write the "scp" command in a console - it is working , and copping the files.

any idea how to solve it?
Thanks.

Revision history for this message
David Santamaría Rogado (howl) said :
#4

Perhaps networks is not started before rc.local is executed or if your backup dir is in another drive different that / is not mounted before. In the case that backupdir is in another driver you could put the pertinent mount command before the scp commands. In the case of the network you should edit /etc/init.d/rc.local to start after net has started, I don't know the exact details about doing this.

Revision history for this message
ofirst (ostolovi) said :
#5

I'll try it tomorrow, or may be change the the link number in the rc directory, so this script will be last.
But, I think I have checked that the network starts before the script, when I used the "insserv" command.

Thanks,
Ofir.

Revision history for this message
Best Amarnath (amarnathjmsc) said :
#6

Hi,

 You want scp command has to be run at the run level right.

 Step 1 :- create a script file (name : scpscript) and add your command in that file.

Step 2 : - Make the file executable. And copy your script to bin.

Step 3 :- Add the script file in /etc/rc.local befor the exit 0 line.
                  ex : just add your command in /etc/rc.local
                           #/etc/rc.local
                               /bin/scpscript ( make sure the file is executable)
                             exit 0

 Try the same with /etc/init.d/rc.local also

Thanks

Revision history for this message
ofirst (ostolovi) said :
#7

Hi,
Thanks David and Amarnath for your answers.
I solved it yesterday in the way that Amarnath wrote, by calling my "scp" script from /etc/rc.local .
However I found that the "insserv" command (I think originally from SUSE systems)
placed automatically the "scp" script in a place in /etc/rc2.d that did not work as it worked on SUSE systems.
Debugging this problem, I found that the network did not start when the "scp" script run, so it could not copy files from another server on boot time.

Thx again for your answers !!!!

Revision history for this message
Amarnath (amarnathjmsc) said :
#8

Welcome