自动化脚本ssh以及telnet发送命令并退出(windows和linux都适用)
来源:程序员人生 发布时间:2016-03-04 12:40:16 阅读次数:3112次
需要安装putty,用到的命令是plink:
PuTTY Link: command-line connection utility
Unidentified build, Jun 23 2015 11:43:58
Usage: plink [options] [user@]host [command]
("host" can also be a PuTTY saved session name)
Options:
-V print version information and exit
-pgpfp print PGP key fingerprints and exit
-v show verbose messages
-load sessname Load settings from saved session
-ssh -telnet -rlogin -raw -serial
force use of a particular protocol
-P port connect to specified port
-l user connect with specified username
-batch disable all interactive prompts
The following options only apply to SSH connections:
-pw passw login with specified password
-D [listen-IP:]listen-port
Dynamic SOCKS-based port forwarding
-L [listen-IP:]listen-port:host:port
Forward local port to remote address
-R [listen-IP:]listen-port:host:port
Forward remote port to local address
-X -x enable / disable X11 forwarding
-A -a enable / disable agent forwarding
-t -T enable / disable pty allocation
⑴ ⑵ force use of particular protocol version
⑷ ⑹ force use of IPv4 or IPv6
-C enable compression
-i key private key file for authentication
-noagent disable use of Pageant
-agent enable use of Pageant
-m file read remote command(s) from file
-s remote command is an SSH subsystem (SSH⑵ only)
-N don't start a shell/command (SSH⑵ only)
-nc host:port
open tunnel in place of session (SSH⑵ only)
-sercfg configuration-string (e.g. 19200,8,n,1,X)
Specify the serial configuration (serial only)
本来1直用plink做隧道代理翻墙用,闲来无聊看了看帮助,不看不知道,1看吓1跳
顺利的解决了之前没有实现的功能,特来记录
实用处景1:产品发给用户以后发现有bug,但是安装的位置只能远程,而且数量很多,这个时候需要对产品升级怎样办,不可能1个个ssh,或网页配置吧,那末自动化ssh发送命令就派上用处了,1个脚本循环ssh,wget固件并并升级1气呵成,之前公司就遇到过
实用处景2:现在有1000块板子出货要贴标签,而之前MAC地址由于某种缘由没记录,这个时候怎样办,也不可能1个个去登陆复制粘贴,再保存到打印机吧,1个脚本打印出来,就是这么任性
ssh登陆运行ls命令:
echo y| plink -ssh root@192.168.1.1 -pw password ls
ssh登陆顺次履行command.txt的命令:
echo y| plink -ssh root@192.168.1.1 -pw password -m command.txt
telnet登陆运行ifconfig并退出:
?echo 'ifconfig ;exit'| plink -telnet 192.168.1.1
另外还有 -ssh -telnet -rlogin -raw -serial
基于这几个核心命令,可以纵情发挥了,用了4年linux,1直耿耿于怀怎样自动远程过去发条命令自动退出
学无止境
版权声明:本文为博主原创文章,未经博主允许不得转载。
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠