首页 > 代码库 > 〖Linux〗bash和expect执行ssh命令行sshcmd.exp

〖Linux〗bash和expect执行ssh命令行sshcmd.exp

 1 #!/usr/bin/expect -f 2 # sudo apt-get install expect 3 # ./ssh.exp user passwd server 4 set user [lrange $argv 0 0] 5 set pass [lrange $argv 1 1] 6 set server [lrange $argv 2 2] 7 set cmds [lrange $argv 3 $argc] 8  9 spawn ssh -o StrictHostKeyChecking=no $user@$server $cmds10 match_max 10000011 expect "*?assword:*"12 send -- "$pass\r"13 send -- "\r"14 interact

使用举例:

  sshcmd.exp user passwd 192.168.1.100 ls -l /

〖Linux〗bash和expect执行ssh命令行sshcmd.exp