Results 1 to 7 of 7
Anyone have a script that would allow a persistent ssh connection to a server, then reading in a line from a local file, sending it with a return to the ...
- 04-03-2008 #1Just Joined!
- Join Date
- Apr 2008
- Posts
- 45
ssh input/output pipe
Anyone have a script that would allow a persistent ssh connection to a server, then reading in a line from a local file, sending it with a return to the remote, reading the next line, sending it, etc, until the file is done.
Thanks so much if you can help.
Mike
- 04-03-2008 #2Just Joined!
- Join Date
- Mar 2008
- Posts
- 26
So you mean like ssh into a box and then read (for example)
"cd /home/"
"grep hello" etc etc from a file? Hmm. TBH, it seems like the kind of thing that expect does. I've had trouble getting SSH to do things automatically, as really, it's not designed for that (it's designed for security more than anything). But then maybe I was doing something different.
I would probably try using awk to make a shellscript from the files contents. If no-one has any better ideas, I'll pop back and give you some tips if you're interested.
- 04-03-2008 #3Just Joined!
- Join Date
- Apr 2008
- Posts
- 45
>So you mean like ssh into a box and then read (for example)
>"cd /home/"
>"grep hello" etc etc from a file?
>I would probably try using awk to make a shellscript from the files contents. If >no-one has any better ideas, I'll pop back and give you some tips if you're >interested.
Sure I would be very interested!
I'm not a programmer but once I can build a little script that does certain things, I can use it and learn from it about scripting.
Here's what I've got which sort of works so far;
sed -e 's:$:\n:' filename | ssh -l 192.168.1.235
This seems to work but it's more complicated than what I need and I have two small problems with it.
For one, the machine won't accept any more than 30 entries at a time so if my file has more than 30 entries, it just bombs.
I need to find a way of sending 30 entries (lines from the file), sleep x, continue with the next 30, etc, until entire file is done, then close connection. It's possible that I might have to logout and log back in for the next 30, I won't know until I try it.
The second part is that I have to put the command in the file since I've not found a way of; reading the next line, sending a command at the start of the line, repeating. Instead, I've had to edit the file and enter the command at the start of each line... messy.
These little tools are so useful sometimes though, it's so cool to know these things. Learning a little bit from each experience leads to a nice set of tools over the years.
Mike
- 04-04-2008 #4Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
Mmmm, if you have no real reason to use a persisten connection, you can always use scp to bring the file, modify it locally, and the scp back it. That will require a password unless you setup ssh keys or something (but ssh would require the same thing nonetheless anyway).
If sshfs is available, then you can mount the remote folder locally as well, and operate on it as if it was a local file.
Doing so in ssh is more difficult, because once you are logged in remotely the script will be stalled, and you will need to run *another* script remotelly...
I see no easy way to do so.
- 04-04-2008 #5Just Joined!
- Join Date
- Apr 2008
- Posts
- 45
>scp back it. That will require a password unless you setup ssh keys or >something (but ssh would require the same thing nonetheless anyway).
Yes, if only the remote had scp
.
Does not seem to be that difficult, just playing around, I've already found a few basic ways of doing this. Now I need to know how to add a command into my string.
Mike
- 04-04-2008 #6Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
- 04-04-2008 #7Just Joined!
- Join Date
- Apr 2008
- Posts
- 45


Reply With Quote
