System: CentOS 6.x
1. Install expect first
The code is as follows |
Copy Code |
Yum-y Install expect |
2. Script content:
The code is as follows |
Copy Code |
Cat auto_svn.sh #!/bin/bash Passwd= ' 123456 ' /usr/bin/expect <<-eof Set Time 30 Spawn ssh-p18330 root@192.168.10.22 Expect { "*yes/no" {send "yes\r"; Exp_continue} ' *password: ' {send ' $passwd \ r '} } Expect "*#" Send "cd/home/trunk\r" Expect "*#" Send "SVN up\r" Expect "*#" Send "exit\r" Interact Expect EOF Eof |
That's a lot easier to write, and a script is covered.
Simple usage and examples of expect
Example of using a script file--Implementing automatic password transmission
code is as follows |
copy code |
#!/usr/bin /expect-f Set Password 123456 #download Spawn SCP root@192.168.1.218:/root/a.wmv/home/yangyz/ Set Timeo UT-a expect "root@192.168.1.218 ' Password:" Set timeout send "$passwordr" Set timeout $ SE nd "EXITR" expect EOF |