shell中嵌套執行expect命令執行個體_linux shell

來源:互聯網
上載者:User

一直都想把expect的操作寫到bash指令碼裡,這樣就不用我再寫兩個指令碼來執行了,搞了一下午終於有點小成就,給大家看看吧.

系統:centos 5.x

1.先安裝expect

複製代碼 代碼如下:

yum -y install expect

2.指令碼內容:

複製代碼 代碼如下:

cat auto_svn.sh
#!/bin/bash
passwd='123456'
/usr/bin/expect <<-EOF
set time 30
spawn ssh -p18330 root@192.168.10.22
expect {
"*yes/no" { send "yes\r"; exp_continue }
"*password:" { send "$passwd\r" }
}
expect "*#"
send "cd /home/trunk\r"
expect "*#"
send "svn up\r"
expect "*#"
send "exit\r"
interact
expect eof
EOF

這樣寫的話,就方便得很多,一個指令碼就包括完了.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.