Python+Dialog開發跳板機腳本
阿新 • • 發佈:2018-05-07
python 跳板機 保壘機 dialog 創建普通用戶、密鑰對,上傳到要控制的機器免密碼
控制機跳腳本代碼展示
[yht@localhost tiaoban]$ cat /etc/profile.d/tiaoban.sh
[ $UID -ne 0 ] && python /scripts/tiaoban/tiaoban.py
目錄結構
[yht@localhost ~]$ cat /scripts/tiaoban/tiaoban.py [yht@localhost ~]$ tree /scripts/tiaoban/ /scripts/tiaoban/ ├── ip_list │?? └── ip.txt ├── menu_list │?? ├── one_menu │?? └── one_option └── tiaoban.py
代碼展示
#!/usr/bin/env python #conding:utf-8 import os,getpass PORT=22 USER=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 %s@%s‘ % (PORT,USER,HOST))
選擇菜單
[yht@localhost ~]$ cat /scripts/tiaoban/menu_list/one_menu
0 web1
1 web2(功能未開發)
2 web3(功能未開發)
3 web4(功能未開發)
4 web5(功能未開發)~~
執行腳本
Python+Dialog開發跳板機腳本