Re: [問題] sudo 執行 expect 問題

看板Linux作者 (kent)時間7年前 (2016/12/15 16:24), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
如果你的目的是ssh自動登錄的話,可以提供我在用的腳本, 例如我公司的內部網址是 192.168.10. 開頭, 登錄 192.168.10.1 只要執行 $./sshp.sh 1 密碼 就可以了 bash shell如下(如果登錄不是root,請自行把root也改成參數): #!/bin/sh alive=$(ping -c4 192.168.10.$1 | grep 'received') password=$2 if [ ! -z "$alive" ]; then sed -i.old /^192\.168\.10\.$1/d ~/.ssh/known_hosts expect -c " set timeout 20 spawn ssh \"root\@192.168.10.$1\" set timeout 5 expect { \"Are you sure you want to continue connecting (yes/no)?\" {send \"yes\r\"} } expect \"password: \" send \"$password\r\" expect \"]# \" interact " else echo 192.168.10.$1 無法連線 fi -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 59.120.253.7 ※ 文章網址: https://www.ptt.cc/bbs/Linux/M.1481790251.A.672.html
文章代碼(AID): #1OKbChPo (Linux)
文章代碼(AID): #1OKbChPo (Linux)