简体   繁体   中英

Changing Scripts from Linux to Python - Automation

i use the following commands and form a script to automate servers using Linux now i would like to automate it in python,i dont know how to write commands for these as i am new to python.

    echo "DISK SPACE"
    echo "--------------------- "
    df -kh

    echo "CPU UTILIZATION"
    prstat 1 1

    echo "MEMORY UTILIZATION"
    echo "---------------------    "
    vmstat 

    echo "LINK STATUS"
    echo "---------------------    "
    egrep -i "link||service" logs/septel.log|tail -20

    echo "Restart log"
    echo "---------------------    "
    tail -10  //newlogs/restart.log

    echo "MENU"
    echo "---------------------    "
    echo "0"|/operations/Menu.pl

    dat=`date +%Y%m%d`
    echo "==================================   "
    echo "EOD "
    cat /b-eod/eodclearlog.log

    echo "mart STP"
    echo "---------------------    "
    tail /logs/mart-stp.log

    echo "TNSPING STATUS"
    echo "=========================================   "
    tnsping rwdb

You have different way to solve your problem. If you need a quick one, you need to know that any shell entry can be used through python subprocess:

from subprocess import call
call(["ls", "-l"])

But if you have time, and you want to power the python API, you should give a look to the OS and SYS libraries:

https://docs.python.org/2/library/os.html https://docs.python.org/2/library/sys.html

Anything written with these lib should be usable from Unix or windows.

And to replicate the behaviour or more fancy command, like tail , you will need to look a bit around. For example this question provide several suggestions: How to implement a pythonic equivalent of tail -F?

Like using the library tailf .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM