免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2228 | 回复: 2

[其他] 测试代码格式 [复制链接]

论坛徽章:
0
发表于 2015-02-03 13:31 |显示全部楼层
  1. #!/bin/bash
  2. # chkconfig: 345 99 10
  3. # description: Startup Script for Oracle Databases
  4. # /etc/init.d/oracle
  5. export ORACLE_SID=oracle
  6. # export ORACLE_HOME_LISTNER=/oracle/product/11.2.0/bin/
  7. export ORACLE_BASE=/apps/oracle
  8. export ORACLE_HOME=/oracle/product/11.2.0
  9. export PATH=$PATH:$ORACLE_HOME/bin
  10. case "$1" in
  11. start)
  12. su oracle -c $ORACLE_HOME/bin/dbstart
  13. touch /var/lock/oracle
  14. echo "OK"
  15. ;;
  16. stop)
  17. echo -n "Shutdown Oracle: "
  18. su oracle -c $ORACLE_HOME/bin/dbshut
  19. rm -f /var/lock/oracle
  20. echo "OK"
  21. ;;
  22. *)
  23. echo "Usage: 'basename $0' start|stop"
  24. exit 1
  25. esac
  26. exit 0
复制代码

论坛徽章:
0
发表于 2015-02-03 13:32 |显示全部楼层
  1. #!/usr/bin/python
  2. import sys   
  3. import os   
  4.    
  5. import atexit   
  6. import time   
  7. import psutil   
  8.    
  9. #print "Welcome,current system is",os.name," 3 seconds late start to get data..."   
  10. time.sleep(3)   
  11.      
  12. line_num = 1   
  13.    
  14. #function of Get CPU State   
  15. def getCPUstate(interval=1):   
  16.     return (" CPU: " + str(psutil.cpu_percent(interval)) + "%")   
  17. #function of Get Memory   
  18. def getMemorystate():   
  19.     phymem = psutil.virtual_memory()   
  20.     buffers = getattr(psutil, 'psutil.virtual_memory().buffers', lambda: 0)()   
  21.     cached = getattr(psutil, 'psutil.virtual_memory().cached', lambda: 0)()   
  22.     used = phymem.total - (phymem.free + buffers + cached)   
  23.     line = " Memory: %5s%% %6s/%s" % (   
  24.         phymem.percent,   
  25.         str(int(used / 1024 / 1024)) + "M",   
  26.         str(int(phymem.total / 1024 / 1024)) + "M"   
  27.     )      
  28.     return line   
  29. def bytes2human(n):   
  30.     """  
  31.     >>> bytes2human(10000)  
  32.     '9.8 K'  
  33.     >>> bytes2human(100001221)  
  34.     '95.4 M'  
  35.     """   
  36.     symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')   
  37.     prefix = {}   
  38.     for i, s in enumerate(symbols):   
  39.         prefix[s] = 1 << (i+1)*10   
  40.     for s in reversed(symbols):   
  41.         if n >= prefix[s]:   
  42.             value = float(n) / prefix[s]   
  43.             return '%.2f %s' % (value, s)   
  44.     return '%.2f B' % (n)   
  45.    
  46.    
  47. def poll(interval):   
  48.     """Retrieve raw stats within an interval window."""   
  49.     tot_before = psutil.net_io_counters()   
  50.     pnic_before = psutil.net_io_counters(pernic=True)   
  51.     # sleep some time   
  52.     time.sleep(interval)   
  53.     tot_after = psutil.net_io_counters()   
  54.     pnic_after = psutil.net_io_counters(pernic=True)   
  55.     # get cpu state   
  56.     cpu_state = getCPUstate(interval)   
  57.     # get memory   
  58.     memory_state = getMemorystate()   
  59.     return (tot_before, tot_after, pnic_before, pnic_after,cpu_state,memory_state)   
  60.    
  61. def refresh_window(tot_before, tot_after, pnic_before, pnic_after,cpu_state,memory_state):   
  62.     os.system("clear")   
  63.     """Print stats on screen."""   
  64.    
  65.    
  66.     #print current time #cpu state #memory   
  67.     print(time.asctime()+" | "+cpu_state+" | "+memory_state)   
  68.         
  69.     # totals   
  70.     print(" NetStates:")   
  71.     print("total bytes:           sent: %-10s   received: %s" % (bytes2human(tot_after.bytes_sent),   
  72.                                                                       bytes2human(tot_after.bytes_recv))   
  73.     )   
  74.     print("total packets:         sent: %-10s   received: %s" % (tot_after.packets_sent,   
  75.                                                                       tot_after.packets_recv)   
  76.     )  
  77.     # per-network interface details: let's sort network interfaces so   
  78.     # that the ones which generated more traffic are shown first   
  79.     print("")   
  80.     nic_names = pnic_after.keys()   
  81.     #nic_names.sort(key=lambda x: sum(pnic_after[x]), reverse=True)   
  82.     for name in nic_names:   
  83.         stats_before = pnic_before[name]   
  84.         stats_after = pnic_after[name]   
  85.         templ = "%-15s %15s %15s"   
  86.         print(templ % (name, "TOTAL", "PER-SEC"))   
  87.         print(templ % (   
  88.             "bytes-sent",   
  89.             bytes2human(stats_after.bytes_sent),   
  90.             bytes2human(stats_after.bytes_sent - stats_before.bytes_sent) + '/s',   
  91.         ))   
  92.         print(templ % (   
  93.             "bytes-recv",   
  94.             bytes2human(stats_after.bytes_recv),   
  95.             bytes2human(stats_after.bytes_recv - stats_before.bytes_recv) + '/s',   
  96.         ))   
  97.         print(templ % (   
  98.             "pkts-sent",   
  99.             stats_after.packets_sent,   
  100.             stats_after.packets_sent - stats_before.packets_sent,   
  101.         ))   
  102.         print(templ % (   
  103.             "pkts-recv",   
  104.             stats_after.packets_recv,   
  105.             stats_after.packets_recv - stats_before.packets_recv,   
  106.         ))   
  107.         print("")   
  108.    
  109. try:   
  110.     interval = 0   
  111.     while 1:   
  112.         args = poll(interval)   
  113.         refresh_window(*args)  
  114.         interval = 1   
  115. except (KeyboardInterrupt, SystemExit):   
  116.     pass  
复制代码

论坛徽章:
0
发表于 2015-02-03 13:34 |显示全部楼层
没有颜色啊。。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP