自動化腳本ssh以及telnet發送命令并退出(windows和linux都適用)
來源:程序員人生 發布時間:2016-03-04 12:40:16 閱讀次數:3322次
需要安裝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直耿耿于懷怎樣自動遠程過去發條命令自動退出
學無止境
版權聲明:本文為博主原創文章,未經博主允許不得轉載。
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈