Answer the question
In order to leave comments, you need to log in
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
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] команда-для-удаленного-хоста)
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?
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.
Indeed, everything turned out to be simple. Thanks Valery Ryaboshapko
ssh remote.server.ru "grep needle /path/to/file"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question