Skip to content
📔 阅读量:

命令行交互

本机命令行交互

普通权限执行

python
from youqu3.cmd import Cmd

Cmd.run("ls")

sudo权限执行

python
from youqu3.cmd import Cmd

Cmd.sudo_run("apt install htop")

expect交互

python
from youqu3.cmd import Cmd

Cmd.expect_run(
    "ssh username@machine_ip 'ls -l'",
    events={'password':'secret\n'}
)

远程命令行交互

普通权限执行

python
from youqu3.cmd import RemoteCmd

RemoteCmd("user", "ip", "password").remote_run("ls -l")

sudo权限执行

python
from youqu3.cmd import RemoteCmd

RemoteCmd("user", "ip", "password").remote_sudo_run("apt install htop")

expect交互

python
from youqu3.cmd import RemoteCmd

# TODO
# RemoteCmd("user", "ip", "password").remote_expect_run("sudo apt install htop")