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

本文介绍如何使用WinSCP在Windows控制器上批量修改多台Linux机器上的文件,并执行特定命令,包括安装软件、配置环境变量、使用bat脚本和执行远程Linux命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

思考一个一键修改多台机器的文件,并执行相应命令的脚本,考虑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功能,从而做到一键搞定所有操作的功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值