简体   繁体   English

批处理脚本输出到网站

[英]Batch script output to website

I have a batch script set up on my DC server to monitor my internet connection and other things but I'd like it to be hosted online on my site instead. 我在DC服务器上设置了一个批处理脚本,以监视我的Internet连接和其他情况,但我希望将其托管在我的网站上。

Does anyone know how to output the results to a log file hosted on a server? 有谁知道如何将结果输出到服务器上托管的日志文件?

Locally this works perfectly: 在本地,这很完美:

@ECHO OFF
:LOOPSTART
echo %date% >> Google-log.txt
echo %time% >> Google-log.txt
ping 8.8.8.8 -n 4 >> Google-log.txt
GOTO LOOPSTART

However I would like it to be on my website so I can see the results without having to log into the server to check the logs. 但是,我希望它可以在我的网站上显示,因此无需登录服务器即可查看结果,而无需查看服务器。

Something like this perhaps? 大概是这样吗?

@ECHO OFF
:LOOPSTART
echo %date% >> 173.252.120.6\Google-log.txt
echo %time% >> 173.252.120.6\Google-log.txt
ping 8.8.8.8 -n 4 >> 173.252.120.6\Google-log.txt
GOTO LOOPSTART

But then I'm not sure how to authorise the user to edit the files? 但是我不确定如何授权用户编辑文件? Is it possible to SSH into a server through a batch script? 是否可以通过批处理脚本SSH到服务器中?

Any help would be massively appreciated. 任何帮助将不胜感激。

If you have an SSH access, you can most probably use an SFTP too. 如果您具有SSH访问权限,则很可能也可以使用SFTP。 So use any command-line SFTP client to upload the output. 因此,请使用任何命令行SFTP客户端上载输出。

For example with WinSCP : 例如,使用WinSCP

@ECHO OFF
:LOOPSTART
echo %date% > Google-log.txt
echo %time% >> Google-log.txt
ping 8.8.8.8 -n 4 >> Google-log.txt

winscp.com /log=winscp.log /command ^
    "open sftp://user:password@173.252.120.6/" ^
    "put -append Google-log.txt" ^
    "exit"

GOTO LOOPSTART

Note how the output file is overwritten in each loop ( > instead of >> after the first echo ) and appended to the remote file (the -append switch), not to re-upload the whole log each time. 请注意如何在每个循环中覆盖输出文件(在第一个echo之后用>而不是>> )并附加到远程文件( -append开关),而不是每次都重新上载整个日志。

For details see the guide to automating SFTP/FTP transfers with WinSCP . 有关详细信息,请参见使用WinSCP自动进行SFTP / FTP传输指南

(I'm the author of WinSCP) (我是WinSCP的作者)

If you have FTP access to the web server, you can easily configure an ftp script. 如果您可以通过FTP访问Web服务器,则可以轻松配置ftp脚本。 The ftp client included with windows allows you to supply a -s flag to specify a script file: ftp -s:myscript.txt Windows附带的ftp客户端允许您提供-s标志来指定脚本文件: ftp -s:myscript.txt

myscript.txt (untested): myscript.txt(未经测试):

open 173.252.120.6 打开173.252.120.6

cd logs cd日志

put Google-log.txt 把Google-log.txt

quit 放弃

You can find more info by starting the ftp client in a command prompt window and typing help . 您可以通过在命令提示符窗口中启动ftp客户端并键入help来找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM