linux expect implements logging in to a remote host and executing sample command code
- 2020-06-07 05:57:16
- OfStack
This paper mainly introduces the linux expect implementation of login remote host and execution of commands related content, sharing for your reference and learning, the following is 1 to see the detailed introduction:
Sample code:
#!/bin/bash
export cmd=$1
expect << 'END'
set cmd "$env(cmd)"
spawn ssh root@192.168.56.1 $cmd
expect {
"(yes/no)?" {send "yes\r";exp_continue}
"password:" {send "root\r";exp_continue}
eof
}
END
explain
conclusion