Tail a file from ssh and mirror to a local file
Solution 1
Yes, you can usee tee for that:
ssh -t remotebox "tail -f /var/log/remote.log" | tee -a /var/log/local.log
This way output will be printed on both stdout and copied over into /var/log/local.log on the system you are running ssh command from.
Solution 2
Just redirect the stdout.
ssh -t remotebox tail -f /var/log/remote.log > local.log
To append to local.log:
ssh -t remotebox tail -f /var/log/remote.log >> local.log
This will write to the local server.
The remote server would only be written to if you include the redirect in the quotes:
ssh -t removebox "tail -f /var/log/remote.log >> remote.log"
Related videos on Youtube
Alessandro Barca
Updated on September 18, 2022Comments
-
Alessandro Barca over 1 year
I'm developing on a RedHat Linux server and the Python version installed is the 2.6. I have a Python script that have to replace a string in a file
.sql
. Each time I run the Python script I pass a different argument that must replace the oldest value inside the same.sql
file.File .sql has a content like this:
SELECT * FROM MY_TABLE WHERE 1=1 AND '1234567890' BETWEEN START_VALUE AND END_VALUE AND JOB = 'EMPLOYEE';
I don't want to use some temporary files for the elaboration, I should have to read the .sql and modify it contextually.
I searched on other posts but I've never found the final solution. I tried to use
re.sub
but I didn't find how to make the replacement in effect inside.sql
. -
SET almost 5 yearsis it possible to do the opposite - to tail local file to the remote server over ssh?
-
MDR about 4 yearsFor MySQL it might have been
SET @END_VALUE = ...
rather thanDECLARE @END_VALUE = ...
-
Alessandro Barca about 4 yearssorry, i forgot to explain that the string i want to replace is the '1234567890' but this works as well. I found a solution while you were answering but it is like your. Read the file with file.read() function that return a 'str' type. Then using re.sub() to replace the string and finally re-write the file with the new value. My issue was to understand the difference between reading a file line-by-line or as a single block (string). Now I understood better. Thank you very much.