iT邦幫忙

0

TELNET 或 SSH 登入後執行批次指令

aqr199 2008-06-03 14:27:0039659 瀏覽
  • 分享至 

  • twitterImage

環境為 WINDOWS 2000 + SP4
有沒有什麼TELNET軟體可以設定或執行批次指令
要連線的平台像CISCO

希望能事先寫好設定檔, 然後可以帶參數, 用程式自動設定

看更多先前的討論...收起先前的討論...
badwufan iT邦新手 3 級 ‧ 2008-06-03 15:19:44 檢舉
Putty好像沒辦法做到可以設定或執行批次指令,或事先寫好設定檔,然後可以帶參數,用程式自動設定喔.
fillano iT邦超人 1 級 ‧ 2008-06-03 16:52:23 檢舉
Connection -> SSH
Remote command裡面應該可以輸入命令
fishk iT邦大師 1 級 ‧ 2008-06-03 23:21:04 檢舉
Putty沒辦法設定或執行批次指令, 但加上PuTTY Connection Manager 就可以了.
fillano iT邦超人 1 級 ‧ 2008-06-04 22:10:17 檢舉
透過putty可以執行遠端的shell script阿,你可以把要做動作做成shell script來試試看。

一些需要輸入的參數,可以用shell script的命令列參數傳進shell script,透過遠端執行也可以在putty裡面輸入shell script的參數喔。
aqr199 iT邦新手 2 級 ‧ 2008-06-04 22:43:22 檢舉
to:fillano
我需要的連線平台是像cisco那一種的
應該不會有shell script可以用
fillano iT邦超人 1 級 ‧ 2008-06-04 23:09:42 檢舉
了解。那就當我沒說。
fillano iT邦超人 1 級 ‧ 2008-06-04 23:16:24 檢舉
對了,putty可以從命令列操作,參考:
http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter3.html#using-cmdline

這樣可以從console做成cmd或是用wsh、powershell等來下命令,批次操作。
建議你可以使用Perl程式來完成,不過你的平台是Windows,需要先安裝ActivePerl,載入net::telnet::cisco模組,相關範例請參考http://nettelnetcisco.sourceforge.net/docs.html。不過我是用linux的shell script完成類似作業:sh ver, sh run,....。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
12
fillano
iT邦超人 1 級 ‧ 2008-06-06 08:08:35
最佳解答

剛剛有看到一些商業ssh元件可以用,只是我也沒嘗試。

http://www.djhd.com/ssh-activex-download.html

有.net跟activex的元件。可以試用30天。

有一段sample code,看起來應該可以做到你要的功能。

<pre class="c" name="code">
Ssh1.Blocking = True
Ssh1.Connect
Debug.Print Ssh1.WaitFor("joe@debian")
Ssh1.Prompt = "joe@debian"
Debug.Print Ssh1.Execute("cd /tmp" & vbLf)
Debug.Print Ssh1.Execute("ls -al" & vbLf)

execute方法還有一個參數讓你可以用字串或regular expression來檢查執行的結果。

28
fishk
iT邦大師 1 級 ‧ 2008-06-03 14:52:17

試試看PuTTY Connection Manager
http://puttycm.free.fr/
這是一套based on PuTTY的免費程式.

如果你還沒裝Putty,可以到下列網址下載.
[
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html](<br />
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)

20
w111927
iT邦好手 1 級 ‧ 2008-06-03 20:01:53

PuTTY很好用也穩定也可用在linux,自己也是用此軟體推薦喔!!

8
ping
iT邦研究生 1 級 ‧ 2008-06-04 16:32:54

推薦PuTTY吧
好像很少有比它更好用的

14
powerop
iT邦研究生 4 級 ‧ 2008-06-04 23:41:32

PuTTY 看來可以用 -m 的參數,執行本地端的指令稿(script)。底下的解說來自 PuTTY 官方網站文件:
3.8 The PuTTY command line

3.8.3.6 -m: read a remote command or script from a file

The -m option performs a similar function to the ‘Remote command’ box in the SSH panel of the PuTTY configuration box (see section 4.18.1). However, the -m option expects to be given a local file name, and it will read a command from that file.

With some servers (particularly Unix systems), you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script; but this is arguably an abuse, and cannot be expected to work on all servers. In particular, it is known not to work with certain ‘embedded’ servers, such as Cisco routers.

This option is not available in the file transfer tools PSCP and PSFTP.

不然,就在 MS Windows 2000 上面裝 cygwin 再裝 expect 吧,可以參考我的網誌:
網管的暗黑系法術:用 expect 和 autoexpect 寫 BBS 機器人,衝上站次數

aqr199 iT邦新手 2 級 ‧ 2008-06-05 00:10:03 檢舉

TO powerop:
內容有提到, it is known not to work with certain ‘embedded’ servers, such as Cisco routers.
看起來是不能符合需求
cygwin加expect 的組合,光是環境的架設就有點複雜, 先不考慮了
謝謝回應

powerop iT邦研究生 4 級 ‧ 2008-06-05 12:49:48 檢舉

Hi aqr199,
那段話的意思,好像只是說,遇到像是 Cisco routers 這一類的系統,-m 後面接的文字檔裡面,可能無法放多行的指令。

不曉得如果只放一行,但是那一行其實是呼叫另一個指令稿(script),這樣行不行?

cygwin 其實可以用一指神功安裝耶,下載 http://www.cygwin.com/setup.exe 回來,然後一直按 next 就可以了。要記得在套件選擇的時候,多選 expect 喔,不然裝好了以後再重新執行這個 setup.exe 加選,也是可以的。

我要發表回答

立即登入回答