D
D
Dmitry Erokhin2015-03-16 10:53:44
linux
Dmitry Erokhin, 2015-03-16 10:53:44

How to copy a string from a file on a remote server?

There is a bash script in which you need to add code that can get into a remote server, get into a file and copy a line from there.
I haven’t come up with anything yet, except how to copy the file remotely to my PC and already here pull out the desired line from it.
But this option is unsuccessful because, in practice, these files will reach 60 mb or more.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
3
3vi1_0n3, 2015-03-16
@erohin_d

The SSH client can execute commands remotely.
To do this:
1) You need to configure key authentication, or use askpass (not a very good option)
2) Use the command
Or immediately write the result to a variable:

RESULT=$(ssh [email protected] команда-для-удаленного-хоста)

M
microphone, 2015-03-16
@microphone

What are the string search criteria? Unique value? or a specific line number?
How to connect to a remote machine via ssh, as I understand it, does not cause problems for you?

S
Sergey, 2015-03-16
@butteff

You can take this line on a remote server and send it through some kind of rsync.
Or even show the line online, then the script from your PC will be able to watch it through wget and redirect I / O streams. Of course, if the string is not top secret. But if so, you can fasten apache authorization. But I'm not sure that in general the solution is not a crutch.

D
Dmitry Erokhin, 2015-03-16
@erohin_d

Indeed, everything turned out to be simple. Thanks Valery Ryaboshapko
ssh remote.server.ru "grep needle /path/to/file"

H
Hanggard, 2015-03-26
@Hanggard

expect

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question