通过winscp实现一键修改多台机器文件,并执行相应命令的脚本

来源:互联网 发布:mac finder打不开 编辑:程序博客网 时间:2024/04/30 11:34

思考一个一键修改多台机器的文件,并执行相应命令的脚本,考虑controller是在windows的情况,agent均为linux,需要使用bat脚本
需要先安装一个软件winscp,然后配置该安装文件的目录到环境变量之中。
执行的主bat脚本如下:
set CURRENT_PATH=%~dp0winscp /script=%CURRENT_PATH%\script.txt  /console /privatekey=%CURRENT_PATH%\agentkety.ppkpause
需要一个执行命令的script.txt脚本,此处只罗列2台机器,留个思路做备份,如下:
# Automatically abort script on errorsoption batch abort# Disable overwrite confirmations that conflict with the previousoption confirm off# Connect using a password# open sftp://user:password@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"# Connectecho goopen sftp://root@ec2-54-251-107-178.ap-southeast-1.compute.amazonaws.com# Change remote directorycd /opt/apache-jmeter-2.9_2013.3.11/bin# Force binary mode transferoption transfer binary# Download file to the local directory d:\get nohup.out d:\put jmeter.logcall cat jmeter.log# Disconnectcloseopen sftp://root@ec2-54-251-107-177.ap-southeast-1.compute.amazonaws.com# Change remote directorycd /opt/apache-jmeter-2.9_2013.3.11/bin# Force binary mode transferoption transfer binary# Download file to the local directory d:\get nohup.out d:\put jmeter.logcall cat jmeter.log# Disconnectclose
其中call命令式用来远程执行linux的shell命令,所以可以通过put上传文件覆盖后,再通过call来执行某些服务的restart功能,从而做到一键搞定所有操作的功能。
0 0
原创粉丝点击