sudo 執行 expect 問題 - Linux

By Edward Lewis
at 2016-12-15T16:24
at 2016-12-15T16:24
Table of Contents
如果你的目的是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
--
例如我公司的內部網址是 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
--
Tags:
Linux
All Comments
Related Posts
Botnet : Ganiw.Botnet

By Yuri
at 2016-12-15T09:58
at 2016-12-15T09:58
sudo 執行 expect 問題

By Elma
at 2016-12-14T21:48
at 2016-12-14T21:48
ubuntu server上建立r-leaflet套件

By Hedy
at 2016-12-14T11:10
at 2016-12-14T11:10
SSH連線加密技術疑問

By Puput
at 2016-12-14T10:14
at 2016-12-14T10:14
SSH連線加密技術疑問

By Rachel
at 2016-12-13T07:20
at 2016-12-13T07:20