控制机跳脚本代码展示
[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(功能未开发)~~
执行脚本
原文地址:http://blog.51cto.com/yht1990/2113592