linux 批量关闭telnet
Posted xl-892694298
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux 批量关闭telnet相关的知识,希望对你有一定的参考价值。
shutdown_telnet.sh
explujing=/home/shutdown_telnet.exp
username=root
password=123456
iplist="
192.167.1.1
192.167.1.2
"
port=22
for ip in $iplist
do
$explujing $ip $username $password $port
done
#-------------------------------------
shutdown_telnet.exp
#!/usr/bin/expect -f
set date [exec date -d day +‘%Y%m%d‘]
set date [exec date -d day +‘%Y%m%d‘]
set desthost [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set port [lindex $argv 3]
set username [lindex $argv 1]
set password [lindex $argv 2]
set port [lindex $argv 3]
expect
"*(yes/no)?"
send "yes\n"
expect "*assword:" send "$password\n"
"*assword:"
send "$password\n"
"*(yes/no)?"
send "yes\n"
expect "*assword:" send "$password\n"
"*assword:"
send "$password\n"
expect "*#"
send "cd /etc\r"
send "cd /etc\r"
expect "*#"
send "mv securetty_bak securetty\r"
send "mv securetty_bak securetty\r"
expect "*#"
send "sed -i \"s/\‘#pts/0\‘/\‘pts/0\‘/g\" /etc/securetty\r"
send "sed -i \"s/\‘#pts/0\‘/\‘pts/0\‘/g\" /etc/securetty\r"
expect "*#"
send "sed -i \"s/\‘#pts/1\‘/\‘pts/1\‘/g\" /etc/securetty\r"
send "sed -i \"s/\‘#pts/1\‘/\‘pts/1\‘/g\" /etc/securetty\r"
expect "*#"
send "sed -i \"s/no/yes/g\" /etc/xinetd.d/telnet\r"
send "sed -i \"s/no/yes/g\" /etc/xinetd.d/telnet\r"
expect "*#"
send "sed -i \"s/#account required pam_nologin.so/account required pam_nologin.so/g\" /etc/pam.d/login\r"
send "sed -i \"s/#account required pam_nologin.so/account required pam_nologin.so/g\" /etc/pam.d/login\r"
expect "*#"
send "cd /root/\r"
send "cd /root/\r"
expect "*#"
send "chkconfig telnet off\r"
send "chkconfig telnet off\r"
expect "*#"
send "service xinetd restsrt\r"
sleep 2;
expect "*#"
send "service xinetd restart\r"
sleep 2;
send "service xinetd restsrt\r"
sleep 2;
expect "*#"
send "service xinetd restart\r"
sleep 2;
expect "*#"
send "exit\r"
interact
以上是关于linux 批量关闭telnet的主要内容,如果未能解决你的问题,请参考以下文章