WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: using bootlocal.sh to scp  (Read 3412 times)

Offline ambaum01

  • Newbie
  • *
  • Posts: 17
using bootlocal.sh to scp
« on: December 27, 2012, 03:15:39 PM »
I am trying to create a text file and write that text file to a server automatically upon boot.  When I execute the following command in terminal after boot, it successfully scps the file:
Quote
scp /home/dir/file.txt username@SERVER:/company/dir

When I put that line of code in bootlocal.sh, I got the error:
 
Quote
ssh: Could not resolve hostname SERVER: Name or service not known
lost connection

So I figured it was a timing thing, so I added a long delay:
Quote
sleep 60
scp /home/dir/file.txt username@SERVER:/company/dir

But now I get the error:
Quote
Host key verification failed.
lost connection

Is this caused by trying to use scp too early in the boot process?  Is there a better way to automatically transfer the file as soon as possible after boot?  Thanks.

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: using bootlocal.sh to scp
« Reply #1 on: December 27, 2012, 07:01:50 PM »
Have you restored all keys in ~/.ssh at boot?
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11634
Re: using bootlocal.sh to scp
« Reply #2 on: December 27, 2012, 07:39:22 PM »
Hi tinypoodle
Since bootlocal.sh runs as root, wouldn't that be  /root/.ssh ?

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: using bootlocal.sh to scp
« Reply #3 on: December 27, 2012, 07:48:59 PM »
Good catch!

Might be a possible explanation why the command works when interactively executed as tc, but not in bootlocal.sh

Alternatively perhaps invoking su(1) to run scp as tc could be an approach.
« Last Edit: December 27, 2012, 10:35:59 PM by tinypoodle »
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11634
Re: using bootlocal.sh to scp
« Reply #4 on: December 27, 2012, 08:04:01 PM »
Hi tinypoodle
So maybe something like
Code: [Select]
su tc -c scp /home/dir/file.txt username@SERVER:/company/dir

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: using bootlocal.sh to scp
« Reply #5 on: December 27, 2012, 09:57:56 PM »
su tc -c 'scp /home/dir/file.txt username@SERVER:/company/dir'
or
su -c 'scp /home/dir/file.txt username@SERVER:/company/dir' tc
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline ambaum01

  • Newbie
  • *
  • Posts: 17
Re: using bootlocal.sh to scp
« Reply #6 on: December 28, 2012, 10:39:57 AM »
su tc -c 'scp /home/dir/file.txt username@SERVER:/company/dir'
This works wonderfully!  Although, I do have to put sleep 1 before it.  Thank you very much!

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: using bootlocal.sh to scp
« Reply #7 on: December 29, 2012, 11:05:57 AM »
Glad I could help, but it was rather Rich pointing out the core of your issue ;)

You omitted to mention which scp you are using, assuming openssh, in case of dropbear an additional parameter of "-i /path/to/identityfile" may be required.
« Last Edit: December 29, 2012, 02:04:33 PM by tinypoodle »
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline ambaum01

  • Newbie
  • *
  • Posts: 17
Re: using bootlocal.sh to scp
« Reply #8 on: January 24, 2013, 12:32:32 PM »
Just to follow up, I did not have to include -i /path/file.  I assume it's because I did not rename the public and private key file names.
Thanks to all who helped out.
-Aaron

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: using bootlocal.sh to scp
« Reply #9 on: January 24, 2013, 06:20:46 PM »
Just to follow up, I did not have to include -i /path/file.
It would be more useful if you could clearly state which ssh version you are using...
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline ambaum01

  • Newbie
  • *
  • Posts: 17
Re: using bootlocal.sh to scp
« Reply #10 on: January 25, 2013, 10:09:46 AM »
I'm using OpenSSH_6.0p1, OpenSSL 1.0.0i 19 Apr 2012

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: using bootlocal.sh to scp
« Reply #11 on: January 25, 2013, 10:32:11 AM »
So that explains why the "-i /path/to/key" may be omitted; OpenSSH searches in a default path, while with dropbear the path option appears to be a mandatory statement (SSL is without relevance).
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)