Documentation ¶
Index ¶
- func CheckCmd(cmd string) bool
- func GetUserInfo(display bool) (ok bool, username string, userid int, UserHome string)
- func Version() string
- type ApiHandle
- type ApiShell
- func (api *ApiShell) AwkCol(col string)
- func (api *ApiShell) Column(col int, sep string) *ApiShell
- func (api *ApiShell) Echo()
- func (api *ApiShell) Grep(match string) *ApiShell
- func (api *ApiShell) Line(n int) *ApiShell
- func (api *ApiShell) ProcessIsRunning(command string) bool
- func (api *ApiShell) RunScript(command ...string)
- func (api *ApiShell) RunShell(command ...string)
- func (api *ApiShell) RunShellList(cs []string)
- func (api *ApiShell) RunTerminal(command ...string)
- func (api *ApiShell) RunTimeout(n time.Duration, command ...string) *ApiShell
- type ApiSudo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetUserInfo ¶
GetUserInfo 获取用户名,用户uid,用户家目录
@Description: @param display 是否显示详细信息 @return ok 获取结果 @return username 用户名 @return userid 用户ID @return UserHome 用户主目录
Types ¶
type ApiShell ¶ added in v1.4.7
type ApiShell struct { PrintErr bool // 打印详细错误信息(默认: true) PrintInfo bool // 是否打印详细信息(默认: false) Debug bool // 是否打印调试信息(默认: false) Realtime bool // 是否开启实时打印信息 Result bool // 是否执行成功 Text string // 需要执行的命令 OsType string // 系统类型 Strings string // 输出结果 ExitCode int // 命令执行退出代码 Err error // 错误 Slice []string // 数据切片 Script string // 脚本文件 ScriptMode bool // 脚本文件 Terminal string // 使用的终端命令 TerminalArg string // 使用的终端参数 TerminalBool bool // 是否可以使用终端 BlackHole bool // 是否使用黑洞模式(忽略错误信息) Ignore bool // 是否忽略标准输出 // contains filtered or unexported fields }
ApiShell @Description: 定义命令的结构体
func NewShell ¶ added in v1.4.6
func NewShell() *ApiShell
NewShell 命令实例构造函数 Realtime 是否开启实时打印数据
@Description: @return *ApiShell
func (*ApiShell) ProcessIsRunning ¶ added in v1.8.0
ProcessIsRunning 通过进程命令检测进程是否存在,例如传入: dpkg
func (*ApiShell) RunScript ¶ added in v1.5.8
RunScript 通过生成脚本的方式执行Shell,支持Shell管道
@Description: @receiver api @param command 需要执行的命令,例如 'apt', 'update',命令与选项可以分开传入
func (*ApiShell) RunShell ¶ added in v1.4.7
RunShell 执行命令
@Description: @receiver api @param command 需要执行的命令,例如 'apt', 'update',命令与选项可以分开传入
func (*ApiShell) RunShellList ¶ added in v1.7.7
RunShellList 批量执行命令
@Description: 通过传入完整的命令切片遍历执行,当遇到执行错误立即返回 @receiver api @param cs 需要执行的命令切片,每个切片元素必须是完整命令
func (*ApiShell) RunTerminal ¶ added in v1.7.8
RunTerminal 通过调用图形化终端程序的方式执行Shell命令,使用脚本封装的方式,支持Shell管道
@Description: @receiver api @param command 需要执行的命令,例如 'apt', 'update',命令与选项可以分开传入
type ApiSudo ¶ added in v1.4.7
type ApiSudo struct { SudoPath string // sudo命令绝对路径 Password string // sudo权限使用的密码 ApiShell // 继承Shell实例 // contains filtered or unexported fields }
ApiSudo 定义命令的结构体
func NewSudo ¶ added in v1.4.6
NewSudo 命令实例构造函数, 当不需要执行sudo命令的时候直接传入任意字符串给password即可
@Description: @param password 主机密码 @return *ApiSudo
func (*ApiSudo) Grep ¶ added in v1.5.8
Grep
@Description: 从结果中筛选关键词 @receiver api @param match @return *ApiSudo
func (*ApiSudo) RunScriptSudo ¶ added in v1.7.0
RunScriptSudo 通过生成脚本的方式执行Shell,支持Shell管道
@Description: @receiver api @param command
func (*ApiSudo) RunSudo ¶ added in v1.7.0
RunSudo 通过sudo执行命令
@Description: @receiver api @param command
func (*ApiSudo) RunSudoList ¶ added in v1.7.7
RunSudoList 通过sudo执行命令
@Description: @receiver api @param cs
Click to show internal directories.
Click to hide internal directories.