[root@rocky8 ~]# vim expect5.sh
#!/bin/bash
#
#**********************************************************************************************
#Author: Raymond
#QQ: 88563128
#Date: 2021-10-22
#FileName: expect5.sh
#URL: raymond.blog.csdn
#Description: The test script
#Copyright (C): 2021 All rights reserved
#*********************************************************************************************
NET=172.31.0
user=root
password=123456for ID in 6 7;do
ip=$NET.$IDexpect <<EOF
set timeout 20
spawn ssh $user@$ip
expect {"yes/no" { send "yesn";exp_continue }"password" { send "$passwordn" }
}
expect "]#" { send "sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/confign" }
expect "]#" { send "setenforce 0n" }
expect "]#" { send "exitn" }
expect eof
EOF
done[root@rocky8 ~]# chmod +x expect5.sh
[root@rocky8 ~]# bash expect5.sh
spawn ssh root@172.31.0.6
root@172.31.0.6's password:
Last login: Fri Oct 22 16:07:11 2021 from 172.31.1.8
[root@centos6 ~]# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@centos6 ~]# setenforce 0
setenforce: SELinux is disabled
[root@centos6 ~]# exit
logout
Connection to 172.31.0.6 closed.
spawn ssh root@172.31.0.7
root@172.31.0.7's password:
Last login: Fri Oct 22 16:07:11 2021 from 172.31.1.8
[root@centos7 ~]# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@centos7 ~]# setenforce 0
setenforce: SELinux is disabled
[root@centos7 ~]# exit
logout
Connection to 172.31.0.7 closed.
[root@rocky8 ~]# vim expect6.sh
#!/bin/bash
#
#**********************************************************************************************
#Author: Raymond
#QQ: 88563128
#Date: 2021-10-22
#FileName: expect6.sh
#URL: raymond.blog.csdn
#Description: The test script
#Copyright (C): 2021 All rights reserved
#*********************************************************************************************
NET=172.31.0
user=root
password=123456
for ID in 6 7;do
ip=$NET.$ID
expect <<EOF
set timeout 20
spawn ssh $user@$ip
expect {
"yes/no" { send "yesn";exp_continue }
"password" { send "$passwordn" }
}
expect "#" { send "useradd testn" }
expect "#" { send "exitn" }
expect eof
EOF
done[root@rocky8 ~]# bash expect6.sh
spawn ssh root@172.31.0.6
root@172.31.0.6's password:
Last login: Fri Oct 22 16:06:48 2021 from 172.31.1.8
[root@centos6 ~]# useradd test
[root@centos6 ~]# exit
logout
Connection to 172.31.0.6 closed.
spawn ssh root@172.31.0.7
root@172.31.0.7's password:
Last login: Fri Oct 22 16:06:47 2021 from 172.31.1.8
[root@centos7 ~]# useradd test
[root@centos7 ~]# exit
logout
Connection to 172.31.0.7 closed.
本文发布于:2024-01-30 15:53:59,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170660124221140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |