批量登陆linux主机脚本
#test.sh #!/bin/bash dir=/home/test while read line do host=`echo $line| awk ‘{print $1}‘` passwd=`echo $line | awk ‘{print $2}‘` $dir/expect_ssh.sh $host $passwd & done < $dir/host.txt #expect_ssh.sh #!/usr/bin/env expect set HOST [lindex $argv 0] set PASSWD [lindex $argv 1] spawn ssh root@$HOST expect "(yes/no)?" { send "yes\n" } expect "*password:" { send "$PASSWD\n" } expect "*password:" { send "$PASSWD\n" } expect "*#" { send "useradd -u 0 -g 0 username\n" } #执行相关操作,比如adduser expect eof #host.txt格式,可从数据库中导出 IP passwd
本文出自 “-=湖边竹=-” 博客,请务必保留此出处http://bronte.blog.51cto.com/2418552/1535807
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。