Solaris_change_passwd使用注意事项及说明 1. 脚本只测试了Solaris10的英文及中文版(oracle公司出品) 2. Solaris10中文版系统需要将系统字符
Solaris_change_passwd使用注意事项及说明
1.
脚本只测试了Solaris10的英文及中文版(oracle公司出品)
2.
Solaris10中文版系统需要将系统字符集改为zh_CN.UTF-8
3.
以bash执行此脚本
bash Solaris_change_passwd 用户名($1) IP地址($2) 用户密码($3) 需要更改密码的用户名($4) 更改的用户密码($5)
脚本变量定义:
#!/bin/bash
USER=$1 #用户名
IP=$2 #IP地址
PW=$3 #用户密码
CHE_USER=$4 #需要更改密码的用户名
CHE_PW=$5 #更改的密码
ping -c 3 ${IP} >/dev/null #ping 3次 $IP地址不输出显示
if [ "$?" -ge "1" ] ;then #如果输出结果大于等于1,则
echo "The network impassability" #输出“The network impassability”
exit 1 #退出此次循环
fi #结束if循环
expect -c " #调用expect脚本
set timeout 30 #设置超时间为30秒
match_max 100000 #设置匹配最大长度为100000
spawn ssh $USER@$IP #调用ssh程序登录
expect {
\"yes\/no\" { send \"yes\n\" ; exp_continue } #匹配到yes/no时,输入yes.继续向下执行
\"assWord: \" { #匹配到“assword”时
send \"${PW}\n\" #输入$PW
expect \"Permission denied\" { #匹配到“Permission denied”时
send_user \"\nUser name password mistake, or no permissions.\n\"
#输出“nUser name password mistake, or no permissions.”
exit 2 #退出2循环
}
}
\"口令: \" { # 匹配到“assword”时
send \"${PW}\n\" # 输入$PW
expect \"Permission denied\" { #匹配到“Permission denied”时
send_user \"\nUser name password mistake, or no permissions.\n\"
#输出“nUser name password mistake, or no permissions.”
exit 3 #退出3循环
}
}
\"Connection refused\" { #匹配到“Connection refused”
send_user \"\nSSH Service is not open\n\" #输出“nSSH Service is not open”
exit 4 #退出4循环
}
}
expect \"*#*\" { send \"passwd $CHE_USER\n\" } #匹配到#号时,输入“passwd $CHE_USER”
expect {
\"assword:\" { send \"$CHE_PW\n\" ; exp_continue } #匹配到assword时,输入 $CHE_PW,继续向下执行
\"口令:\" { send \"$CHE_PW\n\"; exp_continue } #匹配到口令:时,输入 $CHE_PW,继续向下执行
}
expect\"#\" { send \"exit\n\" } #输入exit退出 (实在不行就干掉)
expect eof #结束expect调用脚本
"
用法:bash gaimi.sh root 192.168.0.2 redhat aa 123123
--结束END--
本文标题: expect交互式脚本
本文链接: https://www.lsjlt.com/news/49832.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-16
2024-05-16
2024-05-16
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
2024-05-15
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0