亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 1977 | 回復(fù): 7
打印 上一主題 下一主題

[系統(tǒng)管理] expect 腳本內(nèi)如何自動(dòng)根據(jù)ip的不同,send不同的密碼 [復(fù)制鏈接]

論壇徽章:
1
處女座
日期:2014-04-25 21:29:27
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2015-08-25 15:08 |只看該作者 |倒序?yàn)g覽
我這里現(xiàn)有一個(gè)expect腳本
#!/usr/bin/expect
set Host [lindex $argv 0]
send $Host[0]\n
proc do_command {} {
expect "*$"
send "df -hT\r"
}
spawn ssh -p 22 root@192.168.$Host
set do_done 1
#while ($do_done)
expect {
                "(yes/no)?"     {send "yes\r";exp_continue}
                "*password"     {send "12345678\r"}
}
interact

可以實(shí)現(xiàn)登陸內(nèi)網(wǎng)的服務(wù)器,我們內(nèi)網(wǎng),以及線上的服務(wù)器密碼不同,所以需要兩個(gè)登陸腳本
我想問一下,expect內(nèi)如何分析傳過來的參數(shù),然后再做不同的處理呢?
例如:我們內(nèi)網(wǎng)的ip是192.168.1.*  。線上的ip都是192.168.101.*
如何根據(jù)第三位數(shù)字的不同來進(jìn)行不同的邏輯呢?
我找了許多expect的教程,找到了了一些條件語句的寫法,但是找不到在expect腳本內(nèi)分析字符串的方法,請(qǐng)問各位,有什么辦法嗎

論壇徽章:
16
IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-24 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2015-10-14 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-10-25 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-11-06 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-15 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-21 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2016-08-16 06:20:002015七夕節(jié)徽章
日期:2015-08-21 11:06:17IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-14 06:20:00
2 [報(bào)告]
發(fā)表于 2015-08-25 16:09 |只看該作者
回復(fù) 1# lipengyu1573


    剛好有個(gè)類似的問題,你看下這個(gè) http://blog.chinaunix.net/uid-20778583-id-5168027.html

   跟expect類似,但是python.

   就是加個(gè)判斷呀,if ip == 'xxx'  這種。

論壇徽章:
16
IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-24 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2015-10-14 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-10-25 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-11-06 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-15 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-21 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2016-08-16 06:20:002015七夕節(jié)徽章
日期:2015-08-21 11:06:17IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-14 06:20:00
3 [報(bào)告]
發(fā)表于 2015-08-25 16:10 |只看該作者
expect太簡單,要pexpect辦法就多了,還可以用dict來處理。

論壇徽章:
1
處女座
日期:2014-04-25 21:29:27
4 [報(bào)告]
發(fā)表于 2015-08-25 16:30 |只看該作者
回復(fù) 3# expert1


    額,條件語句我會(huì)寫啊,就是不會(huì)怎么在expect中提出來ip的第三段

聽你的說法,好像做不到?

論壇徽章:
16
IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-24 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2015-10-14 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-10-25 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-11-06 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-15 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-21 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2016-08-16 06:20:002015七夕節(jié)徽章
日期:2015-08-21 11:06:17IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-14 06:20:00
5 [報(bào)告]
發(fā)表于 2015-08-25 16:31 |只看該作者
回復(fù) 4# lipengyu1573


    Google了一下,應(yīng)該是可以的expect本來是基于tcl/tk這個(gè)冷門的語言寫的,

The Control Flow
If Condition
The Syntax:

if { test1 } {
body1
} elseif { test2 } {
body2
} else {
bodyn
}

If you don't like the curly brackets, you can take them out. But then, you will have to give the full thing in one line. I know that after you had a look at that syntax, you are still wondering what in the world that was. Don't worry - an example will set things straight.


#The marriage status script...
#Change the status please
set marital_status "After"

label .thesis -text "Marriage is a three ring circus..."

if { $marital_status=="Before" } {
set ring "Engagement"
} elseif { $marital_status=="During" } {
set ring "Wedding"
} else {
set ring "suffe -"
}

label .proof -text "$marital_status Marriage: $ring ring"

pack .thesis
pack .proof

Run this script and give the 'marital_status' to "Before", "During" and "After" and see the different results.
Operators

You will need operators to do the checking. Fortunately, the operators in Tcl are same as in any other language. So a small experience with any language will guarantee that you know all them.
Tcl has two kinds of operators.
Relational operators: <, <=, >, >=, ==, != return 0 (false) or 1 (true).
Operator in Tcl         Meaning         Example
==        is equal to        5 == 6
!=        is not equal to        5 != 6
<        is less than         5 < 6
<=         is less than or equal to         5 <= 6
>        is greater than         5 > 6
>=        is greater than or equal to         5 >= 6

Logical Operators: && , ! and || operator - AND, NOT and OR Operators.
Operator         Logical Equivalent         Example
! expression        NOT        !$a
expression1 && expression2        AND        $a > 6 && $a < 10
expression1 || expression2        OR        $a != 6 || $a!=5

論壇徽章:
16
IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-24 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2015-10-14 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-10-25 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-11-06 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-15 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-21 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2016-08-16 06:20:002015七夕節(jié)徽章
日期:2015-08-21 11:06:17IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-14 06:20:00
6 [報(bào)告]
發(fā)表于 2015-08-25 16:32 |只看該作者
if的語句如下

if { test1 } {
body1
} elseif { test2 } {
body2
} else {
bodyn
}

判斷一下ip等于多少,send它的密碼過去,這個(gè)真不如python好,直接做個(gè)dict數(shù)據(jù)比較爽。

論壇徽章:
16
IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-24 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2015-10-14 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-10-25 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-11-06 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-15 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-21 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2016-08-16 06:20:002015七夕節(jié)徽章
日期:2015-08-21 11:06:17IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-14 06:20:00
7 [報(bào)告]
發(fā)表于 2015-08-25 16:33 |只看該作者

論壇徽章:
1
CU十四周年紀(jì)念徽章
日期:2015-12-16 18:25:16
8 [報(bào)告]
發(fā)表于 2015-08-25 17:31 |只看該作者
直接用shell判斷然后在調(diào)用expect,就像下面這樣
if  ...;then
echo "[MESSAGE]scp -r -P $port $localPath $user@$ipremotePath"
expect -c "
  spawn  bash $tmpScriptFile
  expect {
    \"$user@$ip*assword:\" {set timeout 3600;send \"$passwd\r\";}
    \"(yes/no)?\" {send \"yes\r\"; exp_continue;}
  }
  expect eof"
else
  ....
fi
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP