Python+Dialog開發跳板機指令碼

來源:互聯網
上載者:User

標籤:python   跳板機   保壘機   dialog   

建立普通使用者、金鑰組,上傳到要控制的機器免密碼

控制機跳指令碼代碼展示

[[email protected] tiaoban]$ cat /etc/profile.d/tiaoban.sh [ $UID -ne 0 ] && python /scripts/tiaoban/tiaoban.py

目錄結構

[[email protected] ~]$ cat /scripts/tiaoban/tiaoban.py[[email protected] ~]$ tree /scripts/tiaoban/       /scripts/tiaoban/├── ip_list│?? └── ip.txt├── menu_list│?? ├── one_menu│?? └── one_option└── tiaoban.py

代碼展示

#!/usr/bin/env python#conding:utf-8import os,getpassPORT=22USER=getpass.getuser()TIAO_BAN_MENU=‘/scripts/tiaoban/menu_list/one_menu‘NUM_FILE_OPTION=‘/scripts/tiaoban/menu_list/one_option‘IP_FILE_OPTION=‘/scripts/tiaoban/ip_list/ip.txt‘os.system(‘dialog --title "Menu" --menu "Level directory" 12 35 5 `cat %s` 2> %s‘% (TIAO_BAN_MENU,NUM_FILE_OPTION))with open(NUM_FILE_OPTION,‘r‘) as f:    NUMBER=f.readline()with open(IP_FILE_OPTION,‘r‘) as f:    line=f.readlines()    HOST=line[int(NUMBER)].strip()os.system(‘ssh -p %s %[email protected]%s‘ % (PORT,USER,HOST))

選擇菜單

    [[email protected] ~]$ cat /scripts/tiaoban/menu_list/one_menu 0 web1 1 web2(功能未開發)2 web3(功能未開發)3 web4(功能未開發)4 web5(功能未開發)~~

執行指令碼

Python+Dialog開發跳板機指令碼

聯繫我們

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