0

I have a text file on one of my computers that is running 12.04. I was planning to use ssh to allow for another computer to read this text file. The issue is that the system that I am working with is basically logging some information on this text file at real time. I need for the computer that is going to read this text file, to read the text file at real time as well.

I am not savvy at all with ssh, but I am familiar with ubuntu. If anyone can provide some insight as to how to do this, or if it is even possible to read this text file at real time while another system is logging info it would be greatly appreciated.

Thank you.

c0rp
  • 9,820
  • 3
  • 38
  • 60
TerNovi
  • 407
  • I don't think so, Because my .txt file is a custom .txt file that needs to be checked, and this file is located on a separate computer. Reading the info off the text file is no problem either. I am looking for something more along the lines of accessing this file remotely without having to use the scp command to copy the file over constantly. – TerNovi Jul 23 '14 at 16:45

2 Answers2

0

What do you mean by "read" the file? If you just want to echo the contents back to the STDOUT, then this should do it.

ssh user@remoteHostName 'tail -f /myDirectory/myFile.txt'

That should work if you have SSH set up properly, "user" is a valid user on your remote host, and the -f flag on the tail command will allow it to view a file as it grows.

Aaron
  • 6,714
  • Let's say that after the file is being echoed out to the stdout, I should be able to read this in a c++ progam... how? – TerNovi Jul 23 '14 at 16:51
  • So are you saying that you want to echo it to another, local file? – Aaron Jul 23 '14 at 16:52
  • Basically I want to read the contents of the file that is located on the other computer, and I have a c++ program that needs to read the contents line by line and perform some calculations to this info. I mean if I can just read stdout line by line it would work. – TerNovi Jul 23 '14 at 16:55
  • I guess you could try using tee to pipe the output from tail to a local file, have your C++ app read that. ssh user@remoteHostName 'tail -f /myDirectory/myFile.txt ' | tee ~/myLocalFile.txt – Aaron Jul 23 '14 at 16:58
  • This sounds like it is going to work. Do you know what will happen if there is no info to tail? For example let's say my system has come to a hault and it is not logging info on the remote computer. Does that mean that the connection ends or it just simply waits for my system to continue logging info? – TerNovi Jul 23 '14 at 17:02
  • If tail is active it will continue logging. – Aaron Jul 23 '14 at 17:20
0

You can use sshfs. Install and setup sshfs.

After setting up sshfs add this 2 alias to your .bashrc.

alias fuse-mo='sshfs remote_user@remote_server:/home/ternovi/your_local_folder /home/remote_user/folder_with_file -o idmap=user -o reconnect'
alias fuse-um='fusermount -u /home/ternovi/your_local_folder'

Now create folder /home/ternovi/your_local_folder with desired path.

If you execute alias fuse-mo, fuse module will mount remote folder to your local folder, and you will see remote files on your local machine in /home/ternovi/your_local_folder. You can work with this files as they are local.

Alias fuse-um will unmount remote file system.

You can use tail -f /home/ternovi/your_local_folder/file.txt to see latest output to this file. Or you can use any editor you want.

For example open file in vim:

vim /home/ternovi/your_local_folder/file.txt

And you can type :e to reload current file.

c0rp
  • 9,820
  • 3
  • 38
  • 60
  • Oh wow... I didn't know that this is possible... – TerNovi Jul 23 '14 at 17:07
  • I think this is more along the lines of what I need. thank you for the info I will give this a shot and see how it works. I might come to you for some help since I am not experienced with ssh at all. – TerNovi Jul 23 '14 at 17:08
  • Feel free to ask – c0rp Jul 23 '14 at 17:09
  • So I followed the instructions on this link to view the mount my drive/directory remotely but i am getting "cannot access folder: Permission Denied" – TerNovi Jul 24 '14 at 13:16