S29.shell脚本每日一练

阅读: 评论:0

S29.shell脚本每日一练

S29.shell脚本每日一练

[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.

58.shell脚本利用循环调用expect在CentOS和Ubuntu上批量创建用户

[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小时内删除。

下一篇:S3C2440 U
标签:脚本   shell
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23