利用Plink替代Putty來建立Script

以往都是用putty這套好用的小程式來連接Server並撰寫Script來自動執行指令。

我的Script資料夾中有一個免安裝的putty,並設定好Session:test01,所以Script有一行指令:putty.exe -load test01。

直到前幾天因為某些原因,重設了另一個資料夾下putty的Session,結果發現原本設定好的test01也不見了。

經查文件後,我才知道putty的設定是放在windows的registery裡面,所以所有的putty都會共用這些設定。


後來在putty的document中發現putty有建議用另一個command line tool:plink來建立script,並提供了許多參數的說明。

document:https://the.earth.li/~sgtatham/putty/0.76/htmldoc/


所以我依文件改寫了scirpt,如下:

plink.exe -ssh -l tt01 -i private.key -batch 192.168.199.126  replication status all


記錄一下我自己的說明:

-ssh:使用ssh協定

-l:指定帳號

-i:private key,我用這個來取代密碼

-batch:取消所有交談提示

192.168.199.126:Server IP

replication status all:連上Server後要執行的指令


詳細的參數說明可以直接下plink或參考document

Windows 11安裝時跳過網路連線