day27:expect批量执行命令|打包挪日记|文本处理|批量删除日记|房贷计算器
1、在linux系统中/root/目录下有一个文件ip-pwd.ini,内容如下: 192.168.149.131,root,nihao123!, 192.168.149.132,root,nihao123@ 每一行的格式分别为linux服务的 IP 用户 密码 ,用一个shell脚本批量查看着看这些服务器的主机名; 脚本代码如下: 一个expect.sh脚本 一个exe.sh脚本,用来调用expect.sh [root@localhost_002 shell]# cat expect.sh #!/usr/bin/expect set port [lindex $argv 0] set host [lindex $argv 1] set passwd [lindex $argv 2] set cm [lindex $argv 3] spawn ssh -p $port root@$host expect { "yes/no" { send "yes\r";exp_continue} "password:" { send "$passwd\r" } } expect "]*" send "$cm\r" expect "]*" send "echo -n yuanhaohao >/tmp/yuanhh.txt\r" expect "]*" send "exit\r" [root