Tiny Core Linux

Tiny Core Base => TCB Q&A Forum => Topic started by: ambaum01 on December 27, 2012, 03:15:39 PM

Title: using bootlocal.sh to scp
Post by: ambaum01 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.
Title: Re: using bootlocal.sh to scp
Post by: tinypoodle on December 27, 2012, 07:01:50 PM
Have you restored all keys in ~/.ssh at boot?
Title: Re: using bootlocal.sh to scp
Post by: Rich on December 27, 2012, 07:39:22 PM
Hi tinypoodle
Since bootlocal.sh runs as root, wouldn't that be  /root/.ssh ?
Title: Re: using bootlocal.sh to scp
Post by: tinypoodle 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.
Title: Re: using bootlocal.sh to scp
Post by: Rich 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
Title: Re: using bootlocal.sh to scp
Post by: tinypoodle 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
Title: Re: using bootlocal.sh to scp
Post by: ambaum01 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!
Title: Re: using bootlocal.sh to scp
Post by: tinypoodle 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.
Title: Re: using bootlocal.sh to scp
Post by: ambaum01 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
Title: Re: using bootlocal.sh to scp
Post by: tinypoodle 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...
Title: Re: using bootlocal.sh to scp
Post by: ambaum01 on January 25, 2013, 10:09:46 AM
I'm using OpenSSH_6.0p1, OpenSSL 1.0.0i 19 Apr 2012
Title: Re: using bootlocal.sh to scp
Post by: tinypoodle 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).