
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、bat脚本:将本地昨天生成的文件,上传到服务器由于工作需要,平生第一次用windows的dos写脚本。 需求:本地有个软件,天天生成相应的log文件,并保存在以日期时光为名目的文件夹下。然后需要在后一天,将前一天生成的log文件及文件夹上传到一个日志服务器举行保存。 实现工具:bat脚本,nc工具,方案任务 其中,由于系统默认的ftp指令行,不支持passive模式,而port模式下,需要修改或开启log生成端服务器的防火墙,需要终于改用网络上免费的小工具ncftp,这个小工具比系统自带的强大了n倍,支持指令行,支持pasv模式也可以切换port模式,还支持断点续传,上传胜利后删除本地文件等。
2、 实现步骤: 1)转到脚本所在名目; 2)上传之前未能胜利上传的文件; 3)取到今日需要上传的文件夹名称; 4)上传今日需要上传的文件夹及文件; 5)假如胜利,删除本地文件,假如不胜利,将文件夹移到备份名目; 6)删除空名目; 以下是详细的脚本内容(英文版系统): - echo off dt=%:10,4%date:4,2%date:7,2% set batpath=%dp0 set dname= rem turn to bat's path %d0 %batpath% bak nul 2 nul rem re-upload bak log directory and file to
3、nms server type %batpath%evtlog.txt | ftpfail nul 2 nul if %errorlevel% equ 0 goto reupload if %errorlevel% neq 0 goto reupend :reupload echo -%dt% re-upload bak log- 2 %batpath%evtlog.txt 1 2 %batpath%ftpput -u adminisator -p password -r 5 -z -r -dd 0 /3 %batpath%bak* 2 %batpa
4、th%evtlog.txt 1 2 if %errorlevel% equ 0 goto cleanrelog if %errorlevel% neq 0 goto reupfailed :cleanrelog cd. %batpath%evtlog.txt for /f tokens=* %a in ('dir /b /ad /s %batpath%bak| /r') do rd %a /q 2 nul goto reupend :reupfailed echo %dt%:ftpfailed reupload files the day before yesterday fa
5、iled! 2 %batpath%evtlog.txt 1 2 goto reupend :reupend rem get the yesterday date for /d %i in (20*) do if %i lss %dt% set dname=%i if ist %dname% goto if not exist %dname% goto :eof :ncftp rem transfer yesterday log file and er to nms server echo -%dt% ftp log- 2 %batpath%evtlog.txt 1 2 %batpath%ncf
6、tpput -u administrator -p password -r 5 -z -r -dd 0 /3 %batpath%dname% 2 %batpath%evtlog.txt 1 2 if %errorlevel% equ 11 goto session if %errorlevel% equ 10 goto library if %errorlevel% equ 9 goto error if %errorlevel% equ 8 goto usage if %errorlevel% equ 7 goto url if %errorlev
7、el% equ 6 goto directoryout if %errorlevel% equ 5 goto directory if %errorlevel% equ 4 goto transfertimeout if %errorlevel% equ 3 goto transfer if %errorlevel% equ 2 goto connecttimeout if %errorlevel% equ 1 goto connect if %errorlevel% equ 0 goto ccess :success echo ncftp:0success. 2 %batpath%evtlo
8、g.txt 1 2 goto exit :connect echo ftpfailed:1could not connect to remote host. 2 %batpath%evtlog.txt 1 2 goto movefile :connecttimeout echo ftpfailed:2could not connect to remote host - timed out. 2 %batpath%evtlog.txt 1 2 goto movefile :transfer echo ftpfailed:3transfer failed. 2 %batpath%evtlog.tx
9、t 1 2 goto movefile :transfertimeout echo ftpfailed:4transfer failed - timed out. 2 %batpath%evtlog.txt 1 2 goto movefile :directory echo ftpfailed:5directory change failed. 2 %batpath%evtlog.txt 1 2 goto movefile :directorytimeout echo ftpfailed:6directory change failed - timed out. 2 %batpath%evtl
10、og.txt 1 2 goto movefile :url echo ftpfailed:7malfoed url. 2 %batpath%evtlog.txt 1 2 goto movefile :usage echo ftpfailed:8usage error. 2 %batpath%evtlog.txt 1 2 goto movefile :error echo ftpfailed:9error in login configuration file. 2 %batpath%evtlog.txt 1 2 goto movefile :library echo ftpfailed:10l
11、ibrary initialization failed. 2 %batpath%evtlog.txt 1 2 goto movefile :session echo ftpfailed:11session initialization failed. 2 %batpath%evtlog.txt 1 2 goto movefile :movefile rem move yesterday log directory s and files to the destination directory bak move /y %batpath%dname% %batpath%bak%dname% 2 %batpath%evtlog.txt 1 2 if %errorlevel% neq 0 echo moveerror:a plie file name exists, or the file cannot be found. 2 %batpath%evtlog.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030比特币挖矿机行业市场现状供需分析及重点企业投资评估规划分析研究报告
- 2025-2030果酒项目商业计划书
- 2025-2030杉木产业行业市场现状供需分析及投资评估规划分析研究报告
- 2025-2030服务外包行业市场发展分析及发展前景与投资机会研究报告
- 水力机械与设备维护考核试卷
- 毛巾生产过程中的自动化技术应用考核试卷
- 渔船动力系统考核试卷
- 数字孪生技术在施工安全领域的应用探索考核试卷
- 尿毒症患者甲状旁腺切除护理
- 新能源与环境保护的关系与作用考核试卷
- 掌握重点中职电子商务教师资格证试题与答案
- 河南省郑州市管城区2024-2025学年级九年级下学期第一次模拟数学试题(原卷版+解析版)
- 隔音涂料施工方案
- 甘肃卷2024年高考真题化学试题(含答案)
- 医院品管圈(QCC)活动成果报告书-基于QFD 润心服务改善 ICU 患者及家属就医体验
- JJG 693-2011可燃气体检测报警器
- 天津科技大学教师公寓租赁管理办法
- 第七章--展示的版面和色彩设计
- DBT29-295-2021 600MPa级高强钢筋混凝土结构技术标准
- Q∕GDW 12164-2021 变电站远程智能巡视系统技术规范
- 钢格构柱组合式塔吊方案(专家认证)
评论
0/150
提交评论