您的位置:首页 > 其它

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

2013-12-12 16:33 615 查看
思考一个一键修改多台机器的文件,并执行相应命令的脚本,考虑controller是在windows的情况,agent均为linux,需要使用bat脚本

需要先安装一个软件winscp,然后配置该安装文件的目录到环境变量之中。
执行的主bat脚本如下:
set CURRENT_PATH=%~dp0
winscp /script=%CURRENT_PATH%\script.txt  /console /privatekey=%CURRENT_PATH%\agentkety.ppk
pause


需要一个执行命令的script.txt脚本,此处只罗列2台机器,留个思路做备份,如下:
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option 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"
# Connect
echo go

open sftp://root@ec2-54-251-107-178.ap-southeast-1.compute.amazonaws.com
# Change remote directory
cd /opt/apache-jmeter-2.9_2013.3.11/bin
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
get nohup.out d:\
put jmeter.log
call cat jmeter.log
# Disconnect
close

open sftp://root@ec2-54-251-107-177.ap-southeast-1.compute.amazonaws.com
# Change remote directory
cd /opt/apache-jmeter-2.9_2013.3.11/bin
# Force binary mode transfer
option transfer binary
# Download file to the local directory d:\
get nohup.out d:\
put jmeter.log
call cat jmeter.log
# Disconnect
close

其中call命令式用来远程执行linux的shell命令,所以可以通过put上传文件覆盖后,再通过call来执行某些服务的restart功能,从而做到一键搞定所有操作的功能。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐