开发者

Automate download logs from server via ssh file transfer to local machine

I need help regarding how to Automate download logs from server开发者_开发百科 via ssh file transfer to local machine.Currently I am downloading logs via login to ssh tool and select the path of the logs and select all the logs and then drag and drop them to local drive but this takes time on VPN. Is there any way to create batch file or run any Java program to downloads all logs just in one line command or single execution automatically.I have tried to check this google but with scp and ftp command I am not able to proceed further.Please suggest.


If you're on Windows, I'd recommend WinSCP's easy scripting.

Just write your script of where to connect, where to navigate to, what to collect and where to copy your file in your machine. You can even copy to another server. All in one script. Examples are easy to follow in the link.

You can also run a simple script that does the work in one line:

winscp.exe /console /command "option batch on" "open rahul@logsserver.com" "get 02012011logs.txt d:\" "exit"


What is the OS you are using for your client? If your client machine is *nix variant, you could write a simple bash script, which when paired with SSH Keys, will allow you your one command downloader.

For a windows variant, you could do similar with a batch script, schedule tasks and pscp w/ pagent saving a private key in memory.

Of course none of this deals with starting up or tearing down the vpn.


Write a batch file that uses pscp to download the files you need. Set up public-key authentication to skip password entry. Enable ssh compression for faster download. Automate it via cron. Theoretically one should be able to use the vpn only for the batch file, practically very difficult to set up that way.


The best option for you would be to write a cron job that copies the log using scp on the regular intervals you want.

However, if you do want to do it in Java. Go for JSch.

Side-note: none of the options above gets you rid of the VPN. You will have to be on VPN to get file transferred, if it's required. So, stay connected to VPN while you are transferring your files in whatever way you like.


Edit

You should update your question with the platform that you're using. My previous answer was assuming that you're on Unix based.

If you are using Windows, you can write a batch script that uses PSCP to transfer the files to your local machine. You can set it as Scheduled Task in Windows to run periodically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜