安装paramiko模块 /usr/local/python36/bin/pip3 install paramiko 1.获取cpu使用率 #!/usr/bin/python #coding=utf8 #target: get the cpu's used of remote linux system import paramiko def getlinux(ssh): # get the result of executing command stdin, stdout, stderr = s
2014年第一个脚本,哈哈!!! expect实现远程主机自动执行命令脚本: #!/usr/bin/expect -- if { [llength $argv] < 4 } { puts "Usage: $argv0 ip user passwd port commands timeout" exit 1 } match_max 600000 set ip [lindex $argv 0] set user [lindex $argv 1] set passwd [lindex
功能说明:用root用户执行一个脚本,脚本里需要切换到普通用户DT去执行其他命令,其中就用到了EOF,用法如下: #!/bin/bash su - DT<<EOF cd apache-tomcat-7.0.54/bin sh startup.sh EOF 当时以为su - DT就跟在交换界面执行一样会把环境也切换过去,所以在分界符EOF里用的是相对路径,结果一运行就报错: -bash: line 8: cd: apache-tomcat-7.0.54/bin: 没有那个文件或目录 然后就做了个