欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

shell腳本怎么實(shí)現(xiàn)ssh自動(dòng)登錄功能-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“shell腳本怎么實(shí)現(xiàn)ssh自動(dòng)登錄功能”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

成都創(chuàng)新互聯(lián)公司專注于原平企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站開(kāi)發(fā)。原平網(wǎng)站建設(shè)公司,為原平等地區(qū)提供建站服務(wù)。全流程定制制作,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)

文件名:ssh_auto_login

代碼如下:


#!/usr/bin/expect
##
# ssh模擬登陸器
#
# @author zhiyuan <hzyhouzhiyuan艾特gmail.com>
##
if {$argc<4} {
 puts "Error params: $argv"
 puts "Expect params :user passwd ip port [translate_id]"
 exit 1
}

set default_passcode "這里填通道機(jī)的默認(rèn)密碼"

set user [lindex $argv 0]
set password [lindex $argv 1]
set ip [lindex $argv 2]
set port [lindex $argv 3]
set timeout 10

while 1 {
 spawn ssh -p $port $user@$ip
 #如果最后的字符匹配則執(zhí)行命令\r結(jié)尾表示確定
 expect {
  "*yes/no" { send "yes\r";exp_continue}
  "*password:" { send "$password\r" }
 }
        #這里是需要通過(guò)通道機(jī)登陸時(shí)的匹配流程,根據(jù)需要自行修改。
 expect {
  "*PASSCODE:" {
   send_user "請(qǐng)輸入通道機(jī)動(dòng)態(tài)密碼:";
   expect_user -re "(.*)\n"
   set random_passcode $expect_out(1,string)
   send "$default_passcode$random_passcode\r"
   expect {
    "Access Denied" { continue }
    "Enter:" { send "1\r" }
   }
   set translate_ip [lindex $argv 4]
   if { $translate_ip != "" } {
    expect "*):" { send "$translate_ip\r" }
   }
  }
  #"Last login:*" { }
 }
 break
}
#無(wú)法匹配$,還不知道怎么解決
#expect -re "*\$" { puts "test123"; send "source /etc/profile\r" }
#expect "*\$" { send "cd ~\r" }
send_user "login success!"
interact


上邊是ssh的自動(dòng)登錄,可以配合下邊的shell使用,很方便。
文件名:xxx_launcher


代碼如下:


#!/bin/sh
##
# 服務(wù)器登陸器
#
# @author zhiyuan <hzyhouzhiyuan@gmail.com>
##
channel_user="user_namexxx"
channel_passwd="xxxx"
#內(nèi)網(wǎng)通道機(jī)
internal_ip1=xxx.xxx.xxx.xxx
#聯(lián)通
unicom_ip1=xxx.xxx.xxx.xxx
#電信
telecom_ip1=xxx.xxx.xxx.xxx
case "$1" in
 ci)
  expect ssh_auto_login $channel_user $channel_passwd $internal_ip3 22

 cl)
  expect ssh_auto_login $channel_user $channel_passwd $unicom_ip1 22

 cd)
  expect ssh_auto_login $channel_user $channel_passwd $telecom_ip1 22

 149)
  expect ssh_auto_login channel_user channel_passwd xxx.xx.xxx.xxx 22

 49)
  expect ssh_auto_login $channel_user $channel_passwd $unicom_ip1 22 需要通道機(jī)跳轉(zhuǎn)的ipxxx.xxx.xx

 *)
  echo "幫助信息:"
  echo "\tthere is not a server named [$1]"
  echo "\t服務(wù)器149:\t149"
  echo "\t服務(wù)器49:\t49"

esac


此時(shí)登陸某個(gè)服務(wù)器的時(shí)候就直接 用上述shell帶要登錄的服務(wù)器參數(shù)即可,如: ./xxx_launcher 49

“shell腳本怎么實(shí)現(xiàn)ssh自動(dòng)登錄功能”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

本文名稱:shell腳本怎么實(shí)現(xiàn)ssh自動(dòng)登錄功能-創(chuàng)新互聯(lián)
路徑分享:http://www.chinadenli.net/article34/dhisse.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化網(wǎng)站設(shè)計(jì)公司定制網(wǎng)站企業(yè)網(wǎng)站制作網(wǎng)站設(shè)計(jì)網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司