Python UNIX系统管理指南
时间:2022-07-23
本文章向大家介绍Python UNIX系统管理指南,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
一本个人感觉很不错的书,这些文章算是实践
自带的终端来运行命令
chmod a+x是加读写权限
两个python,前面是目录,后面是选择解释器
#! /usr/bin/env python
#A System Information Gathering Script
import subprocess
#Command 1
uname = "uname"
uname_arg = "-a"
print ("Gathering system information with %s command:n" % uname)
subprocess.call([uname, uname_arg])
#Command 2
diskspace = "df"
diskspace_arg = "-h"
print ("Gathering diskspace information %s command:n" % diskspace)
subprocess.call([diskspace, diskspace_arg])
#! /usr/bin/env bash
#A System Information Gathering Script
#Command 1
UNAME="uname -a"
printf "Gathering system information with the $UNAME command: nn"
$UNAME
#Command 2
DISKSPACE="df -h"
printf "Gathering diskspace information with the $DISKSPACE command: nn"
$DISKSPACE
你看以上的脚本的时候,其实是可以看的出来。输出几乎一样的。
那么call的时候将命令和参数分开写是不必要的。完全可以这样写
subprocess.call("df -h",shell=True")
python
bash
编写你个简单的函数
#! /usr/bin/env bash
#A System Information Gathering Script
#Command 1
function uname_func ()
{
UNAME="uname -a"
printf "Gathering system information with the $UNAME command: nn"
$UNAME
}
#Command 2
function disk_func ()
{
DISKSPACE="df -h"
printf "Gathering diskspace information with the $DISKSPACE command: nn"
$DISKSPACE
}
function main ()
{
uname_func
disk_func
}
Main
#! /usr/bin/env python
#A System Information Gathering Script
import subprocess
#Command 1
def uname_func():
uname = "uname"
uname_arg = "-a"
print ("Gathering system information with %s command:n" % uname)
subprocess.call([uname, uname_arg])
#Command 2
def disk_func():
diskspace = "df"
diskspace_arg = "-h"
print ("Gathering diskspace information %s command:n" % diskspace)
subprocess.call([diskspace, diskspace_arg])
#Main function that call other functions
def main():
uname_func()
disk_func()
main()
成功
失败,应该是语法错误
不加权限,就运行不了
把下文的main()改成这样,变成可福用脑本
我们来考虑找个东西,输出好像一样,那么它是真的一样吗?
print语句使用的是非正式的字符串表达式
简单变量名使用的事正式的字符串表达式
在处理自定义类时,这差异会变得十分明显
这个老东西写的不好~
我们创建了一个DoubleRep的类,里面有两个类
在实例化对象以后,指定对象df来保存该对象
- SqlServer:此数据库处于单用户模式,导致数据库无法删除的处理
- jQuery中排除指定元素,同时选择剩下的所有元素
- windows客户机连接gerrit的一个报错处理
- 装箱与值类型虽然很容易理解,但是在实际使用中,并不总是能100%用对
- Jexus 配置ssl
- 局部打印插件 jquery.PrintArea.js
- FluorineFx应用中“页面长时间不动”导致无法连接的解决办法
- Mysql主从同步(1)-主从/主主环境部署梳理
- mysql主从同步(3)-percona-toolkit工具(数据一致性监测、延迟监控)使用梳理
- 网站压力测试软件WebBench以及压测Jexus
- Gershon Dublon & Nan Zhao:用传感器网络感知世界
- 即日起珠海可用微信乘公交,腾讯乘车码助力智慧城市建设
- 利用mk-table-checksum监测Mysql主从数据一致性操作记录
- mysql主从同步(4)-Slave延迟状态监控
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法