mac下快捷登入線上伺服器指令碼

來源:互聯網
上載者:User

## 快捷登入線上伺服器指令碼
> 背景環境:原先故障警示,登入故障機查看時非常不討好的事情,密碼強度高,禁止root登入都是只能複製粘貼密碼再登入,非常繁瑣,索性切換到mac下之後這個登入指令檔,直接go <ip最後一段即可>直接登入,省心多了,原先只能複製粘貼密碼方式進行登入故障機檢查警示

===
> 所以借鑒別人指令碼改了如下,登入線上伺服器可以直接利用:# go 210就登入192.168.199.210,root的身份,避免了複製粘貼密碼帶來的時間損耗,前提你得將指令碼所在路徑加入到環境變數中才能這樣使用

```
#!/bin/sh
#filename: go

if [ $# -eq 0 ]
then
echo "Usage: $0 [last_segment_in_ip]"
exit 1
fi

segment=$1
suffix=192.168.199

#if [ -n "$pass" ]; then
ip="$suffix.$segment"
/Users/mingmings/auto_login/login $ip
```

呼叫指令碼如下
```
#!/usr/bin/expect -f
#filename: login
trap {
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH

set timeout 20
set ip [lindex $argv 0]

#set password [exec cat $passbook | grep -v "^#" | grep -w "$ip" | awk {{print $NF}}]
#set root_password [exec cat $root_passbook | grep -v "^#" | grep -w "$ip" | awk {{print $NF}}]

spawn ssh -p xxxx superadmin@$ip

expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" {
# send "$password\r";
send "你懂的\r";
send "su -l\r";
exp_continue;
}
"Password:" {
# send "$root_password\r";
send "你懂的\r";
}
"密碼 " {
send "你懂的\r";
exp_continue;
}
"su: incorrect password" {
send "exit\r";
}
}
interact
```

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.