相信大家也有使用過 putty 操控 linux server, 但如何利用 batch script 連接 linux ?
答案就是 plink.
首先以 notepad 輸入以下命令:
plink -ssh [host] -l [user] -pw [password]
如: plink -ssh 10.0.0.1 -l root -pw Passw0rd
然後另存為 abc.bat 放在 plink 的資料夾中便可
那如何執行 script ?
例如我希望 restart proxy server 的 dansguardian service, 那便...
plink -ssh 10.0.0.1 -l root -pw Passw0rd service dansguardian restart
亦可同時執行數個 command, 如:
plink -ssh 10.0.0.1 -l root -pw Passw0rd ls; service dansguardian restart
便會先執行 ls, 再執行 service dansguardian restart
那我們便可以用 task scheduler 排定工作了 ~
============================
PuTTY Link: command-line connection utility
Unidentified build, Nov 21 2005 12:41:01
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
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
-1 -2 force use of particular protocol version
-4 -6 force use of IPv4 or IPv6
-C enable compression
-i key private key file for authentication
-m file read remote command(s) from file
-s remote command is an SSH subsystem (SSH-2 only)
-N don't start a shell/command (SSH-2 only)