linux下expect環境安裝以及簡單腳本測試
網上的原貼:
expect是交互性很強的腳本語言,可以幫助運維人員實現批量管理成千上百臺服務器操作,很實用!
expect依賴於tcl,而linux系統裏一般不自帶安裝tcl,所以需要手動安裝
下載:expect-5.43.0.tar和tcl8.4.11-src.tar
下載地址:https://pan.baidu.com/s/1kVyeLt9
提取密碼:af9p
安裝前提:需要安裝gcc,可以參考:
redhat 5.1安裝gcc.docx;
將expect和tcl的軟件包下載放到/usr/local/src目錄下
(1)解壓tcl,進入tcl解壓目錄,然後進入unix目錄進行編譯安裝
[root@xw4 src]# tar -zvxf tcl8.4.11-src.tar.gz
[root@xw4 src]# cd tcl8.4.11/unix
[root@xw4 unix]# ./configure
[root@xw4 unix]# make && make
(2)安裝expect
[root@xw4 src]# tar -zvxf expect-5.43.0.tar.gz
[root@xw4 src]# cd expect-5.43.0
[root@xw4 expect-5.43.0]# ./configure --with-tclinclude=/usr/local/src/tcl8.4.11/generic --with-tclconfig=/usr/local/lib/
[root@xw4 expect-5.43.0]# make && make install
(3)安裝完成後進行測試
[root@xw4 ~]# expect
expect1.1>
expect1.1>
實驗結果:
安裝1中,
[root@xw4 unix]# ./configure
有報錯:
checking system version (for dynamic loading)... ./configure: line 7624: syntax error near unexpected token `)'
./configure: line 7624: ` OSF*)'
然後執行下一步:
[root@localhost unix]# make && make
make: *** No targets specified and no makefile found. Stop
原因,是由於tcl8.4.11-src.tar的問題,檢查本機的linux版本參數:
[root@localhost ~]# cat /proc/version
Linux version 2.6.18-53.el5xen ([email protected]) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-14)) #1 SMP Wed Oct 10 17:06:12 EDT 2007
換成tcl8.4.19-src.tar.gz解決;
安裝2中執行:
[root@xw4 expect-5.43.0]# ./configure --with-tclinclude=/usr/local/src/tcl8.4.11/generic --with-tclconfig=/usr/local/lib/
出錯:
checking for Tcl configuration... configure: error: /usr/lib/ directory doesn't contain tclConfig.sh
原因:
tclConfig.sh的位置錯誤,
[root@localhost ~]# find / -name "tclConfig.sh"
/usr/local/src/tcl8.4.19/unix/tclConfig.sh
修改命令後執行:
./configure --with-tclinclude=/usr/local/src/tcl8.4.19/generic --with-tclconfig=/usr/local/src/tcl8.4.19/unix/
運行成功!
下面爲網盤中的安裝文檔及所依賴的安裝包:
http://pan.baidu.com/s/1qYLFZkC