shell下使用expect遍历服务器

1 篇文章 0 订阅
1 篇文章 0 订阅
#服务器IP地址数组
ips=(
ip1...
ip2...
ip3...
...
)
#遍历数组
for ip in ${ips[*]}
do
	/usr/bin/expect<<-EOF   #shell中使用expect
	set timeout 90
	spawn ssh user@$ip
	expect "passphrase"
	send "password\r"
	expect "user"
	send "cd /dir\r"
	expect "dir"
	send "cat file.properties\r"
	expect "propertiy"
	exit
	interact
	expect eof
	EOF
done
#遍历请求ip服务器
ips=(
ip1
ip2
...
)
for ip in ${ips[*]}
do
        url="http://"${ip}"/..."
	echo $ip
	resp="$(curl -s "$url")"  #-s 去掉一些请求头信息
	echo "$resp" 
	result=`echo "$resp" | grep "<message>ok</message>"`  #resp变量必须加引号,否则遇到xml格式文字显示会乱序
	#echo $result
	if [ "$result" != "" ]
	then
		echo "测试通过"
	else
		echo "测试失败"
	fi
done

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值