欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

linux下expect環(huán)境的安裝以及簡(jiǎn)單腳本測(cè)試-創(chuàng)新互聯(lián)

這篇文章主要介紹“l(fā)inux下expect環(huán)境的安裝以及簡(jiǎn)單腳本測(cè)試”,在日常操作中,相信很多人在linux下expect環(huán)境的安裝以及簡(jiǎn)單腳本測(cè)試問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”linux下expect環(huán)境的安裝以及簡(jiǎn)單腳本測(cè)試”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)城口免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了近1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

一、安裝expect和tcl

(1)、解壓tcl,進(jìn)入tcl解壓目錄,然后進(jìn)入unix目錄進(jìn)行編譯安裝

[root@slient tmp]# tar -xzvf tcl8.4.11-src.tar.gz 

..................................

[root@slient tmp]# cd tcl8.4.11/unix/

[root@slient unix]# ./configure

..................................

[root@slient unix]# make && make install

..................................

(2)、安裝expect

[root@slient tmp]# tar -xzvf expect-5.43.0.tar.gz 

..................................

[root@slient tmp]# cd expect-5.43

[root@slient expect-5.43]# ./configure --with-tclinclude=/tmp/tcl8.4.11/generic --with-tclconfig=/usr/local/lib/

..................................

[root@slient expect-5.43]# make && make install

..................................

(3)、安裝完成后進(jìn)行測(cè)試

[root@slient expect-5.43]#  expect

expect1.1> 

expect1.1> 

二、下面結(jié)合shell腳本做簡(jiǎn)單測(cè)試

示例:從本機(jī)自動(dòng)登錄到遠(yuǎn)程機(jī)器192.168.56.12(端口是22,密碼是:oracle)

登錄到遠(yuǎn)程機(jī)器后做以下幾個(gè)操作:

1)useradd wangshibo

2)mkdir /opt/test

3) exit自動(dòng)退出

[root@slient ~]# cat test-ssh.sh 

#!/bin/bash

passwd='oracle'

/usr/local/bin/expect <<-EOF

set time 30

spawn ssh -p22 root@192.168.56.12

expect {

"*yes/no" { send "yes\r"; exp_continue }

"*password:" { send "$passwd\r" }

}

expect "*#"

send "useradd wangshibo\r"

expect "*#"

send "mkdir /opt/test\r"

expect "*#"

send "exit\r"

interact

expect eof

EOF

[root@slient ~]# 

--執(zhí)行:

[root@slient ~]# sh test-ssh.sh 

spawn ssh -p22 root@192.168.56.12

The authenticity of host '192.168.56.12 (192.168.56.12)' can't be established.

RSA key fingerprint is 16:8d:5a:fb:f2:58:e1:ee:4c:98:3d:76:ec:48:bb:46.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.56.12' (RSA) to the list of known hosts.

root@192.168.56.12's password: 

Last login: Tue Jan 30 15:58:08 2018 from 192.168.56.1

[root@one ~]# useradd wangshibo

[root@one ~]# mkdir /opt/test

[root@one ~]# 

[root@slient ~]# 

[root@slient ~]# 

上面的例子如果只是自動(dòng)登陸,登陸機(jī)器后不做操作的腳本內(nèi)容如下:

shell腳本的寫法:

[root@slient ~]# cat test.sh 

#!/bin/bash

passwd='oracle'

/usr/local/bin/expect <<-EOF

set time 30

spawn ssh -p22 root@192.168.56.12

expect {

"*yes/no" { send "yes\r"; exp_continue }

"*password:" { send "$passwd\r" }

}

expect eof

EOF

[root@slient ~]# 

 

--執(zhí)行:

[root@slient ~]# sh test.sh

spawn ssh -p22 root@192.168.56.12

root@192.168.56.12's password: 

Last login: Tue Jan 30 16:03:23 2018 from 192.168.56.20

[root@one ~]# 

expect腳本的寫法:

[root@slient ~]# cat test

#!/usr/local/bin/expect

set timeout 30

spawn ssh -p22 root@192.168.56.12

expect "*password:"

send "oracle\r"

interact

[root@slient ~]# 

--執(zhí)行: 

[root@slient ~]# ./test 

spawn ssh -p22 root@192.168.56.12

root@192.168.56.12's password: 

Last login: Tue Jan 30 16:07:23 2018 from 192.168.56.20

[root@one ~]# 

注意:spawn后面跟的是操作動(dòng)作,比如登陸機(jī)器后執(zhí)行uptime,即:spawn ssh -p22 root@192.168.1.201 "uptime"

三、示例使用expetc自動(dòng)化傳送文件到遠(yuǎn)程主機(jī)目錄上

[oracle@slient ~]$ cat sftp.sh

#!/usr/local/bin/expect

expect<<!

spawn  sftp oracle@192.168.56.12

expect  "password:"

send "oracle\n";

expect "sftp>"

send "lcd /home/oracle/dmp\n";

expect "sftp>"

send "cd  /home/oracle/soft\n";

expect "sftp>"

send "put tb_pt.dmp\n";

expect "sftp>"

send "exit\n"

interact

!

[oracle@slient ~]$

[oracle@slient ~]$ chmod +x sftp.sh 

--執(zhí)行:

[oracle@slient ~]$ sh sftp.sh

spawn sftp oracle@192.168.56.12

Connecting to 192.168.56.12...

oracle@192.168.56.12's password: 

sftp> lcd /home/oracle/dmp

sftp> cd  /home/oracle/soft

sftp> put tb_pt.dmp

Uploading tb_pt.dmp to /home/oracle/soft/tb_pt.dmp

tb_pt.dmp                                                                                                     100%  216KB 216.0KB/s   00:00    

sftp> [oracle@slient ~]$ 

[oracle@slient ~]$ 

--驗(yàn)證:

[oracle@one soft]$ pwd

/home/oracle/soft

[oracle@one soft]$    

[oracle@one soft]$ ls

[oracle@one soft]$ pwd

/home/oracle/soft

[oracle@one soft]$ ls

tb_pt.dmp

[oracle@one soft]$ 

四、示例解釋

例子:

#!/usr/bin/expect

#set timeout 20 #設(shè)置超時(shí)時(shí)間

spawn ssh root@192.168.43.131

expect "*password:"

send "123\r"

# expect "*#"

interact

解釋:

1.#!/usr/bin/expect :需要先安裝軟件,然后來說明用expect來執(zhí)行

2.spawn ssh root@192.168.43.131 :spawn是進(jìn)入expect環(huán)境后才可以執(zhí)行的expect內(nèi)部命令,用來執(zhí)行它后面的命令。

3.expect "*password:" :也是expect的內(nèi)部命令,用來解惑關(guān)鍵的字符串,如果有,就會(huì)立即返回下面設(shè)置的內(nèi)容,如果沒有就看是否設(shè)置了超時(shí)時(shí)間。

4.send "123\r":這時(shí)執(zhí)行交互式動(dòng)作,與手工輸入密碼等效,在expect截獲關(guān)鍵字之后,它就會(huì)輸入send后面的內(nèi)容。

5.interact :執(zhí)行完畢后把持交互狀態(tài),把控制臺(tái),這時(shí)候就可以進(jìn)行你想要進(jìn)行的操作了。如果沒有這一句,在登陸完成之后就會(huì)退出,而不是留在遠(yuǎn)程終端上。

到此,關(guān)于“l(fā)inux下expect環(huán)境的安裝以及簡(jiǎn)單腳本測(cè)試”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

網(wǎng)頁名稱:linux下expect環(huán)境的安裝以及簡(jiǎn)單腳本測(cè)試-創(chuàng)新互聯(lián)
轉(zhuǎn)載來于:http://aaarwkj.com/article38/dgocpp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、品牌網(wǎng)站制作、商城網(wǎng)站、標(biāo)簽優(yōu)化網(wǎng)頁設(shè)計(jì)公司外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司
亚洲综合国产一区二区| 国产a情人一区二区国产| 欧美日韩国产精品乱人伦| 天天干天天干夜夜操| 精品毛片av一区二区三区| 亚洲精品在线观看毛片| 日本高清不卡在线播放| 国产精品一区二区三区四区久久| 午夜视频在线观看区一| 国产一级一片内射视频| 日韩欧美中文字幕一区二区| 欧美一区二区三区中文字幕| 欧美亚洲伊人久久综合| 激情一区二区三区视频| 中文字幕乱码亚州精品一区| 日本精品中文字幕人妻| 日韩欧美亚洲另类视频| 丰满少妇在线观看网站| 欧美日韩综合精品无人区| 国产精品久久久久久老熟女| 激情影院在线观看福利| 国产精品对白久久久久粗| 中文字幕精品人妻在线| 四虎在线观看精品一区| 日本一区二区三区伦理| 亚洲第一精品国产日韩| 日韩不卡免费在线视频| 日韩爱爱特级视频中文字幕| 亚洲一区精品中文字幕| 精品亚洲一区二区在线| 这里只有精品国产999| 国产乱国产乱老熟部视频| 国产91精品网站在线| 国产超碰久久久久久精品| 国产高清剧情在线观看| 九七青青草视频在线观看| 人妇乱系列中文字幕人妻| 亚洲国产精品福利在线| 亚洲最新一区二区在线观看| 亚洲精品熟女国产中文| 亚洲中文字幕在线乱码|