因为项目的需要,天天得分析服务器的LOG,每天都重复做下载工作,不累死,也得烦死。
因为公司的服务器都是LINUX 都架设FTP然后跑任务不太现实,只能通过SCP做了
解决这个问题需要用到WINSCP
首先,安装WINSCP 然后新建一个主机并保存密码
编写一个脚本,并保存到winscp的目录下,命名为sample.txt
# winscp.exe /console /script=sample.txt
# Automatically answer all prompts negatively not to stall
# the script on errors
# option echo on|off
option echo off
# option batch on|off|abort|continue
option batch on
# option confirm on|off
option confirm off
# option transfer binary|ascii|automatic
# option synchdelete on|off
# option exclude clear | <mask>[;<mask2>...]
# option include clear | <mask>[;<mask2>...]
# open [ sftp|ftp|scp:// ][ <user> [ :password ] @ ] <host> [ :<port> ]
# open user:password@example.com
# Connect FTP地址
#open ftp://用户名:密码@outftp.test.com:21
open scp://用户名:密码@192.168.0.100
# Change remote directory
# cd /home/user 如果同步到远程FTP时,可用此命令转到远程某个目录下.
cd /var/log/apache
# Change local directory
# set to Self’s working dir 设置需要同步到远程FTP的本地文件目录
#lcd D:\Temp\Test_Ftp
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
#get examplefile.txt d:\
# option synchdelete on|off
option synchdelete off
# option include clear | <mask>[;<mask2>...]
# option include /2008-*-*/;/2009-*-*/;/2010-*-*/;/2011-*-*/;/2012-*-*/;/2013-*-*/
# synchronize local|remote|both [ <local directory> [ <remote directory> ] ]
从远程同步到本地用Local;从本地同步到远程用Remote
synchronize local D:\weblog\
# Disconnect
close
# Exit WinSCP
exit
再写一个简单的BAT,保存到winscp的目录下,命名为taks.bat
cd \Program Files\WinSCP
WinSCP.exe /console /script=sample.txt
exit
OK 大功告成。接下来就是设置windows的计划任务了,这个就不详细描述了! 每天零点把LOG下回来早上6点的时候自动跑日志分析软件。
