一、安装 TCCLI
git clone https://github.com/TencentCloud/tencentcloud-cli.gitcd tencentcloud-clipython setup.py install
二、shell脚本
vim create-cvm.sh
#!/bin/bash#set -x#在脚本相同目录下创建cvm_id_list.txt文件,把需要重装系统实例ID(每个ID占一行)复制到此文件中保存。if [电脑 ! -f cvm_reset_log.txt];then touch 电脑 cvm_reset_log.txtfifor cvm_id in 电脑`cat cvm_id_list.txt`do tccli cvm ResetInstance --cli-unfold-argument --region ap-beijing --InstanceId ${cvm_id} --ImageId img-9qabwvbn --LoginSettings.Password qaz@WSX123456. &>> cvm_reset_log.txt if [ "$?" != 0 ];then echo -e "\e[1;33;41m $cvm_id reset failed \e[0m" continue #break else echo -e "\e[32m tccli $cvm_id exec completed,results in cvm_reset_log.txt \e[0m" fidone
三、赋予脚本执行权限并运行脚本。
chmod +x create-cvm.shsh create-cvm.sh
电脑