Send file to server when its online

Hi, i save my nginx logfiles to the usb stick in the R7800 router, and using logrotate to rotate and compress them. Now i have a virtual machine with ubuntu with ELK to analyse the logfiles. This machine can be off for a few days as i am only switching it on when needed. Is there a way to automatically copy/move the files on the usb stick to the ubuntu server when this server comes online? With thanks to psherman, i am now thinking about using some kind of script like https://gist.github.com/Harold-D/0f2d7ae3070ceb5d10aa83e8a8c43758 to check if the server is online, and then use ssh with keys to login to the ubuntu server and move the files from the stick to the server. Anyone some advice or tips?
Thanks.

I don't have a direct answer for you, but I can suggest the following:

  1. Just setup a syslog server on the ubuntu VM (assuming it will be online most of the time). Then you don't have to worry about transferring the files after the fact.
  2. If you do need to transfer the files, just create a script and run it as a cron job. A signal such as a successful ping could kick off the script to copy the files over to the VM. To prevent sending the files multiple times, it might make sense to either manage the files locally such that the script does not send them again. A simple option would be to delete the files from the USB stick once they have been transferred. Or you could create a mechanism for marking them as transferred... this could be done in a number of ways -- move them to a "transferred" directory, change the filename, create a file that contains the most recent file transferred by the file's date and/or filename, create a log file of all transferred files to date (appending each time) and parse that to only send those files not in the list, etc.
1 Like