使用脚本发送ssh命令

时间:2011-06-10 15:24:37

标签: networking scripting ssh ksh

我想通过运行./script:

来检查Nortel路由器
#!/bin/ksh
print "IP:"
read ip;
ping ${ip};
ssh -l default ${ip} "sho mod; en; sho int; sho node-e; sho node-a";

我可以正常地使用     ssh -l [user] [ip]。

但不是     ssh -l [user] [ip]'[cmd1],[cmd2]'它会自动显示“Conection to [ip] closed。”

1 个答案:

答案 0 :(得分:1)

有一个名为expect的应用程序可以为您进行这种交互/终端模拟。否则,您可以使用fabric编写脚本,甚至可以使用paramiko

直接在python中编写脚本

以这种方式运行命令当然会更好,但如果您的路由器不接受这种方式的命令,则需要模拟标准连接。