標籤:python shell
1.
cmd = "some unix command"retcode = subprocess.call(cmd,shell=True)
2.
ssh = paramiko.SSHClient()ssh.connect(server, username=username, password=password)ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd_to_execute)
3.
import commandscommand = "nslookup " + node + " | grep Name -1 | grep Address| awk ‘{print $2}‘"result = commands.getoutput(command)if (result == ""): return "unknown"
4.
sshProcess = subprocess.Popen([‘ssh‘, <remote client>], ,stdin=subprocess.PIPE, stdout = subprocess.PIPE)sshProcess.stdin.write("ls mydirectory\n")sshProcess.stdin.write("echo END\n")for line in stdout.readlines(): if line == "END\n": break print(line)sshProcess.stdin.write("uptime\n")sshProcess.stdin.write("echo END\n")for line in stdout.readlines(): if line == "END\n": break print(line)
本文出自 “Linux和網路” 部落格,轉載請與作者聯絡!
Python調用shell的幾種方式