## 快捷登陸線上服務器腳本
> 背景環境:原先故障報警,登陸故障機查看時很是不討好的事情,密碼強度高,禁止root登陸都是隻能複製粘貼密碼再登陸,很是繁瑣,索性切換到mac下以後這個登陸腳本,直接go <ip最後一段便可>直接登陸,省心多了,原先只能複製粘貼密碼方式進行登陸故障機檢查報警服務器
===
> 因此借鑑別人腳本改了以下,登陸線上服務器能夠直接利用:# go 210就登陸192.168.199.210,root的身份,避免了複製粘貼密碼帶來的時間損耗,前提你得將腳本所在路徑加入到環境變量中才能這樣使用ssh
```
#!/bin/sh
#filename: gospa
if [ $# -eq 0 ]
then
echo "Usage: $0 [last_segment_in_ip]"
exit 1
fiip
segment=$1
suffix=192.168.199it
#if [ -n "$pass" ]; then
ip="$suffix.$segment"
/Users/mingmings/auto_login/login $ip
```ast
調用腳本以下
```
#!/usr/bin/expect -f
#filename: login
trap {
set rows [stty rows]
set cols [stty columns]
stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCHawk
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@$ipfile
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```