Tiny Core Linux

Tiny Core Base => TCB Q&A Forum => Topic started by: ambaum01 on December 12, 2012, 10:38:22 PM

Title: Problems trying to write a text file to a network location
Post by: ambaum01 on December 12, 2012, 10:38:22 PM
I am very new to tiny core and am having trouble recreating the results of an existing script running on Ubuntu.  On the Ubuntu machine, I am writing the file using this code:

eval spawn scp /home/kamal/log.txt user@SERVER:/company/manufacturing/dir

This code works fine on Ubuntu, but is giving me problems with tiny core.  I keep getting the error that the directory is invalid.  Are there additional steps I need to take?
Thanks for any help, as I really do appreciate it.  This is not only my first adventure with tiny core, but with linux in general.
-Aaron
Title: Re: Problems trying to write a text file to a network location
Post by: tinypoodle on December 12, 2012, 10:49:28 PM
Did you double check your paths?

Which ssh client are you using?
Title: Re: Problems trying to write a text file to a network location
Post by: ananix on December 13, 2012, 01:40:41 PM
Think you need to be more precise

are you running the script in tcl or just that one line?

Im guessing the script.

Is that the precise error?

Im guessing not, im guessing it says "No such file or directory"

what is giving you that error?

Im guessing bash

so when you run your script you get this

-bash: /usr/sbin/expect: No such file or directory

what scripting language are you using?

The first line of your ubuntu script should state the interpreter path with a #!

Maybe it points to "expect"

In that case you need to install inspect.

Maybe im all wrong and you actualy wrote a precise description.

Can i ask what you are trying to achive?
Title: Re: Problems trying to write a text file to a network location
Post by: ambaum01 on December 13, 2012, 02:05:11 PM
Did you double check your paths?

Which ssh client are you using?
The path is good (as it works with the Ubuntu machine), but I do not know what ssh client I am using.  It just seems to work on the Ubuntu machine fine.

Think you need to be more precise

are you running the script in tcl or just that one line?

Im guessing the script.

Is that the precise error?

Im guessing not, im guessing it says "No such file or directory"

what is giving you that error?

Im guessing bash

so when you run your script you get this

-bash: /usr/sbin/expect: No such file or directory

what scripting language are you using?

The first line of your ubuntu script should state the interpreter path with a #!

Maybe it points to "expect"

In that case you need to install inspect.

Maybe im all wrong and you actualy wrote a precise description.

Can i ask what you are trying to achive?

I am running the following script
Quote
#!/usr/bin/expect -f

set server SERVERNAME

eval spawn cp /home/kamal/log.txt username@SERVERNAME:/company/dir
match_max 100000
expect "username@servername's password: $"
send -- "password\n"

expect "$ $"

The exact error I receive:
Quote
cp: can't create 'username@SERVERNAME:/company/dir': Path does not exist
Nothing that says bash, it simply prints the above line.

I am assuming that the language is expect?  I have installed the expect extension in tcl.  All I really need to do is take a file called log.txt that is created on this tcl machine and place it in a specific directory on our server.  The problem with this is that our old setup works fine and was developed by a different engineer who no longer works for the company.  now I am stuck with fixing this to work with a machine running tcl.  Hopefully I can figure this out.  Thanks!
-Aaron
Title: Re: Problems trying to write a text file to a network location
Post by: gerald_clark on December 13, 2012, 02:21:22 PM
You state that you are trying to scp a file, but your script does a cp.
That is scp syntax, not cp.
Title: Re: Problems trying to write a text file to a network location
Post by: tinypoodle on December 13, 2012, 02:40:46 PM
...while in OP it was indeed scp...

A top level dir named "/company" would be most unorthodox in the least...
Title: Re: Problems trying to write a text file to a network location
Post by: ambaum01 on December 13, 2012, 02:50:39 PM
You state that you are trying to scp a file, but your script does a cp.
That is scp syntax, not cp.

Is the scp command supported in tcl?  When I tried running this script with scp, it said scp not found, so I tried changing it to cp.  I also removed 'eval spawn' because it was having trouble with those.  This is all due to my lack of knowledge, just trying to brute force through this to get a working solution.
So, I've changed the code back to:
Quote
#!/usr/bin/expect -f

set server SERVERNAME

eval spawn scp /home/kamal/log.txt username@SERVERNAME:/company/dir
match_max 100000
expect "username@servername's password: $"
send -- "password\n"

expect "$ $"

and it gives me the error:
Quote
scpfiles.sh: eval: line 1: spawn: not found
couldn't read file "username@servername's password: $": no such file or directory
scpfiles.sh: line 12: send: not found
couldn't read file "$ $": no such file or directory
Title: Re: Problems trying to write a text file to a network location
Post by: Rich on December 13, 2012, 02:54:19 PM
Hi ambaum01
scp is available from the  openssh.tcz  extension.
Title: Re: Problems trying to write a text file to a network location
Post by: gerald_clark on December 13, 2012, 03:07:37 PM
Did you install the openssh or dropbear extension?
Title: Re: Problems trying to write a text file to a network location
Post by: ambaum01 on December 13, 2012, 03:11:14 PM
Hi ambaum01
scp is available from the  openssh.tcz  extension.
Wonderful!  So now I have written log.txt to the required directory.  Thank you so much.

I am now having a problem with the password entry.  It seems as if the expect statement is not working.  I already have the expect extension loaded, so i know that is not the issue.  After the scp command, it immediately prompts me for the password, which should be taken care of by the expect command, but obviously it is not.  Any ideas?  Thanks so much!

Current code:
Quote
#!/usr/bin/expect -f

set server SERVERNAME

scp /home/kamal/log.txt username@SERVERNAME:/company/dir
match_max 100000
expect "username@servername's password: $"
send -- "password\n"

expect "$ $"

Did you install the openssh or dropbear extension?
I have not installed these extensions, but the file is being written now.  Do I need them?
Title: Re: Problems trying to write a text file to a network location
Post by: gerald_clark on December 13, 2012, 03:29:36 PM
I would recommend setting up key authentication for your scp.
Title: Re: Problems trying to write a text file to a network location
Post by: ambaum01 on December 13, 2012, 04:24:28 PM
I would recommend setting up key authentication for your scp.
After quickly looking this up, I'm willing to bet it is way over my head.  This scpfiles.sh script runs fine when it comes to network auth on the Ubuntu machine.  Is there any reason why the same wouldn't work with tcl?
Title: Re: Problems trying to write a text file to a network location
Post by: Rich on December 13, 2012, 08:44:34 PM
Hi ambaum01
Just a guess on my part::
Code: [Select]
cd /usr/local/etc/ssh/
cp sshd_config.example sshd_config
editor sshd_config
Change the line that reads
Code: [Select]
#ChallengeResponseAuthentication yesto
Code: [Select]
ChallengeResponseAuthentication noThen run:
Code: [Select]
/usr/local/etc/init.d/openssh restartSee if it still prompts you for a password.
Title: Re: Problems trying to write a text file to a network location
Post by: tinypoodle on December 13, 2012, 09:52:55 PM
Key authentication would be as recommendable under ubuntu, regardless of the toolkit vs. kitchen sink difference.
Title: Re: Problems trying to write a text file to a network location
Post by: ambaum01 on December 13, 2012, 10:05:07 PM
Hi ambaum01
Just a guess on my part::
Code: [Select]
cd /usr/local/etc/ssh/
cp sshd_config.example sshd_config
editor sshd_config
Change the line that reads
Code: [Select]
#ChallengeResponseAuthentication yesto
Code: [Select]
ChallengeResponseAuthentication noThen run:
Code: [Select]
/usr/local/etc/init.d/openssh restartSee if it still prompts you for a password.

Thank you for your help.  I'll give this a go and report back.
Title: Re: Problems trying to write a text file to a network location
Post by: ambaum01 on December 13, 2012, 10:21:37 PM
Hi ambaum01
Just a guess on my part::
Code: [Select]
cd /usr/local/etc/ssh/
cp sshd_config.example sshd_config
editor sshd_config
Change the line that reads
Code: [Select]
#ChallengeResponseAuthentication yesto
Code: [Select]
ChallengeResponseAuthentication noThen run:
Code: [Select]
/usr/local/etc/init.d/openssh restartSee if it still prompts you for a password.

No luck, it is still prompting me for a password as it was before.
Title: Re: Problems trying to write a text file to a network location
Post by: Rich on December 13, 2012, 10:31:00 PM
Hi ambaum01
As I said, it was just a guess.
Title: Re: Problems trying to write a text file to a network location
Post by: ambaum01 on December 13, 2012, 10:32:31 PM
I appreciate it just the same.  this is a pretty frustrating problem.  If I could just get past this hurdle I think I could make this thing work.
Title: Re: Problems trying to write a text file to a network location
Post by: tinypoodle on December 13, 2012, 10:59:20 PM
Instead of trying to circumvent ssh security, you could as well consider to look into nc and netcat the file content.
Title: Re: Problems trying to write a text file to a network location
Post by: Rich on December 13, 2012, 11:15:50 PM
HI tinypoodle
I don't think he's trying to circumvent ssh security. He's trying to get the script to submit the password.
Title: Re: Problems trying to write a text file to a network location
Post by: ambaum01 on December 13, 2012, 11:57:22 PM
HI tinypoodle
I don't think he's trying to circumvent ssh security. He's trying to get the script to submit the password.
This exactly.
Title: Re: Problems trying to write a text file to a network location
Post by: Rich on December 14, 2012, 12:23:06 AM
Hi ambaum01
I've never worked with expect myself, but suspect the problem may be in the script. For example:
Code: [Select]
expect "username@servername's password: $"This is what expect is looking for from ssh. It's very specific, so if your syntax for the response is not exactly right, it
will fail. I recommend Googling    linux expect scp example    to find a better starting point for a more robust script.
Google will return a lot of examples related to what you want with that search phrase.
Title: Re: Problems trying to write a text file to a network location
Post by: tinypoodle on December 14, 2012, 08:48:02 AM
HI tinypoodle
I don't think he's trying to circumvent ssh security. He's trying to get the script to submit the password.

Your statement leaves me puzzled...   :-\
Perhaps you mean to disagree on semantics while agreeing in essence?
Title: Re: Problems trying to write a text file to a network location
Post by: Rich on December 14, 2012, 12:10:24 PM
Hi tinypoodle
If you consider a script circumventing security, then yes, I disagree on semantics while agreeing in essence.
Title: Re: Problems trying to write a text file to a network location
Post by: Lee on December 14, 2012, 04:51:29 PM
Hi ambaum01,

There is an expect related thread here: http://forum.tinycorelinux.net/index.php/topic,14493.0.html that relates to sending an ssh password using expect.  I have a script similar similar to the one shown there that puts or gets a file using scp and using expect to provide the password.

In my case, probably due to some oddity in my system (and my systems -do- have the occasional oddity), these things only work as root (sudo ... ), but they do work.

Of course there are security concerns with embedding passwords in scripts...
Title: Re: Problems trying to write a text file to a network location
Post by: ambaum01 on December 18, 2012, 09:07:22 AM
Thanks for the suggestions.  I will do some more research on this forum and elsewhere to get this solved.  I've always wanted a reason to become familiar with Linux, and as frustrating as some of this has been, I have been learning a great deal.  I greatly appreciate everyone's advice thus far.
Title: Re: Problems trying to write a text file to a network location
Post by: ambaum01 on December 27, 2012, 01:02:13 PM
I finally resolved this issue using ssh.  It turns out it was much easier to implement than I initially thought.  I've run into a different issue, but I will post it in another thread.  Thanks again.